How to fix "Guru Meditation Error" caused by http.GET();? - http-get

I want to send data on my web server from esp32. ESP32 can not get to website and reboot.
I used exaples from Arduino IDE.
I've tried to post(htt.POST("X")) something and got same error.
I marked code to find which line cause the problem.
Googled.
...
msg="192.168.4.22/parametr";
if(WiFi.status() == WL_CONNECTED){
if(client.connect(host,httpPort)){
http.begin(msg);
Serial.print("0");
Serial.print("[HTTP] GET...\n");
int httpCode = http.GET();
Serial.print("1");
...
I expect to get to website, but now esp32 reboots when achived http.GET() and never prints "1".
Error message: Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

The URL you are passing to http.begin() is incorrect. You need to include the http:// prefix (see here). Semantically, it makes more sense to name this variable url rather than msg.
Also ... Check the return value of http.begin() - in case it is still failing.
const char *url = "http://192.168.4.22/parametr";
// Check Wi-Fi connected, etc.
if (!http.begin(url)) {
Serial.println("HTTP client failed to connect ...");
}
else {
int httpCode = http.GET();
// etc.
}
The LoadProhibited fatal error indicates an attempt to read or write an invalid memory location. When the library failed to parse the URL you provided, some member of the HTTPClient object may have been left uninitialized.
Log output
To assist your debugging, try setting the 'Core debug level' in the Arduino IDE to 'Debug'.
Arduino IDE -> Tools -> Core Debug Level -> Debug
This will ensure that the ESP log messages - such as might be printed if initialization of the HTTP client fails - will be printed over the serial port.
For example, this is the log output I see if I fail to include the http:// protocol specifier in the URL (after changing the core debug level).

Related

HttpClient->GetStringAsync() throws 0x000006F4 for https Uris

The code below works fine for me if I use an http URI, but fails for equivalent https alternative. It works fine when built and run on another machine or when I include it in another app.
GetStringAsync throws an exception: “Exception thrown at 0x770B5722 (KernelBase.dll) in .exe: 0x000006F4: A null reference pointer was passed to the stub. occurred”.
ThreadPool::RunAsync(ref new WorkItemHandler([this](IAsyncAction^ action)
{
HttpClient^ client = ref new HttpClient();
auto uri = ref new Uri(L"https://....");
auto t = create_task(client->GetStringAsync(uri));
t.then([](String^ response)
{
// response should be valid.
});
}));
Running netsh winsock reset to reset the network stack seems to fix the issue!
For me, network stack reset didn't help at all, even device reboot didn't help, but your own answer have pointed me in the right direction: it wasn't my code who suddendly went mad, it was Windows. So what actually helped in my case is starting app without debugger (that is, from Start menu) - after that app continues to work fine when started from Visual Studio. It have happened a few times now, and I can confirm that it always helps.

Error while running VS Webtest

While running a simple visual studio webtest (ensure that my SERVER responds appropriately to a GET request), I get an appropriate response (i.e. the value for the key I'm passing as a parameter). However, the test fails with the following error:
"Request failed: Value cannot be null.
Parameter name: uriString"
and the only available stacktrace reading:
System.ArgumentNullException: Value cannot be null.
Parameter name: uriString
at System.Uri..ctor(String uriString, UriKind uriKind)
at Microsoft.VisualStudio.TestTools.WebStress.WebTestInstrumentedTransaction.ProcessCompletedRequest(Boolean completedSynchronously)"
I don't use a uriString variable anywhere in my code.
Any suggestions on how to fix this?
Figured it out, and it wasn't an issue with the test. My setup was responding with a 302, which needs a redirection header that was not being populated (I intended to use a 200, but confused HTTPStatusCode Found with OK), which caused the above

loopback + remote calls + debug

if there is a server error, my XHR will return a 500 error code along with a vague description.
what is the best practice on viewing error logs, debug output, etc?
can this output be sent to my console?
what will work for me now is using the debug object.
var debug = require('debug')('my:debug:string');
then specifying the debug string when launching the app.
DEBUG=my:debug:string node .

Actionscript 4: NetConnection.connect(...) does not fire a NetStatusEvent event

I downloaded the red5-recorder (http://www.red5-recorder.com/) , which fails to allow me to start recording. After debugging I found that the netconnection, needed to record to a media server, created does not fire a NetStatusEvent event, so essentially it fails silently. I have implemented the connection with the following minimal working example:
trace("make net connection");
nc = new NetConnection();
nc.client = { onBWDone: function():void{ trace("bandwidth check done.") } };
trace("add event listener");
nc.addEventListener(NetStatusEvent.NET_STATUS, function(event:NetStatusEvent) {
trace("handle");
});
trace("connect!");
nc.connect("rtmp://localshost/oflaDemo/test/");
trace("connect done");
The output of this piece of code is:
make net connection
add event listener
connect!
connect done
The actionscript api states that the connect-call always fires such an event:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetConnection.html#includeExamplesSummary
Moreover, the netconnection is not 'connected' (a state of the NetConnection object) 10 seconds after the call. I also took a look at this: NetConnect fails silently in Flash when called from SilverLight But the fix suggested by the author, swapping rtmp and http in the connection uri, do not work. Also, I tested the uri and in fact the exact same code sniplet in a personal project, where it did work. I just can not seem to find why connecting to a media server fails silently in the red5-recorder project.
The awkward part is that if I pass some random string as a conenction uri, still nothing happens (no event, no exception, no crash). Also not setting nc.client becore nc.connect(), which caused exceptions in my experience, did not cause exceptions.
Any suggestions are welcome.
You are setting the address to localshost instead localhost.
nc.connect("rtmp://localshost/oflaDemo/test/");
Correct address:
nc.connect("rtmp://localhost/oflaDemo/test/");

BinaryReader.Read does not throw IOException when the connection is lost

I use HttpWebResponse.BeginGetResponse() method to make a request to my server. The request has AllowReadStreamBuffering set to false so that the data will not be buffered. In the "Request Complete" notification I do the following (no error handling code included):
HttpWebResponse response = (HttpWebResponse)myHttpWebRequest.EndGetResponse(result);
BinaryReader streamReader = new BinaryReader(response.GetResponseStream());
try
{
while ((readSize = streamReader.Read(buffer, 0, buffer.Length)) > 0)
{
...
}
}
catch (Exception)
{ // NEVER GET HERE!!
...
}
My problem is that I cannot detect connection errors during reading data from stream (during the while loop). The behavior is very strange: it finishes to read all data that the OS has in the cache and then returns 'readSize = 0' as in the case of "end of stream".
I was expecting streamReader.Read() to throw an IOException exception but it does not!
I tried to find a stream failed flag somewhere but it seems that there is none (Stream/BinaryReader/HttpWebResponse). Please help!
I tested this by using three scenarios and all had the same behavior:
Using the phone-to-PC USB connection
Phone connected to Internet using the PC USB connection
After few streamReader.Read() successful calls I disable the PC network card
Using WIFI connection
Phone connected to Internet using WIFI connection
After few streamReader.Read() successful calls I power off the WIFI router
Using WIFI connection
Phone connected to Internet using WIFI connection
After few streamReader.Read() successful calls I remove WAN cable (so it has no Internet access).
Thank you!
Mihai
If you are not getting an exception then one option is to check the number of bytes read against response.ContentLength

Resources