Apparently, the HttpClient library croaks because the E4 did not return an HTTP result code (eg. 200), just the data string. Unfortunately, Sensatronics is no longer with us so a firmware upgrade is out of the question.
Now I’d be happy to play with this myself but when I included the library directly into my code to make some changes, it wouldn’t compile, complaining something about multiple class definitions or some such C++ mumbo jumbo.
So does anyone know either:
how to get HttpClient to return a result when the provider doesn’t give a result code,
or how to get the HttpClient library to compile
or some other low-cost temperature sensor that provides a network REST API I can query successfully?
You could use TCPClient and construct the HTTP request yourself instead of using HTTPClient.
That's probably because both the imported and the locally included libraries still exist in your project.
Try removing the imported version by hitting the (x) icon next to the library name
If that doesn't help, create a new project where you never imported the library but only add your local copy of the lib.
Ah ha - once again you gave me the answer. TCPClient worked just fine. Thank you so much. For the benefit of anyone else who might want to read a Sensatronics temperature server, here is some code that works:
#include "application.h"
char resultstr[64];
char buffer[64] = {" "} ;
char sub[12] ;
int nextTime = 0;
int bytesRead ;
int c = 0 ;
TCPClient client;
byte server[] = { 192, 168, 0, 117 };
void setup()
{
// Make sure your Serial Terminal app is closed before powering your device
Serial.begin(9600);
// Wait for a USB serial connection for up to 30 seconds
waitFor(Serial.isConnected, 30000);
Serial.println("connecting...");
if (client.connect(server, 83))
{
Serial.println("connected");
client.println("GET /temp HTTP/1.0");
// client.println("Host: 192.168.0.117");
// client.println("Content-Length: 0");
client.println();
delay (1000) ;
}
else
{
Serial.println("connection failed");
}
if (client.available())
{
// char c = client.read();
bytesRead = client.read ((uint8_t*)buffer, 64);
Serial.print ("buffer=") ;
Serial.println (buffer);
while (c < 4)
{
sub[c] = buffer[9+c-1];
c++;
}
Serial.print ("sub=") ;
Serial.println (sub);
}
if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;);
}
}
void loop() {
}