Open xxvms opened 7 years ago
Hi @xxvms,
Merry Christmas!
The line you are showing looks correct to me. What about the rest of the query string? Sending more variables is shown in next sections, for instance in 8-Automate.
The part of code printing confirmation to the console is very simple. It is not actively waiting for reply from Emoncms. This creates a problem that you are likely to miss error message, if query sting is incorrect and response slow,
Check my other repository EspToCloud that contains slightly more advanced version of this code that is waiting for response from server. It also contains program flow diagram explaining how it works.
If you use this code instead, you should be able to see confirmation from Emoncms if the data have been correctly received.
Krzysztof
Hi Krzychb
thanks for that, I overcome the issue by creating new function in the sketch, not sure if there was better way, but this one worked. I will check your suggestion as for some reason I didn't get to see that.
void sendDataToEmoncmsHumidity(void)
{
if (client.connect(emoncmsServer, 80))
{
String getJSON = "";
getJSON += "GET http://" + (String) emoncmsServer;
getJSON += "/input/post.json?json={Humidity:" + (String) humidity +"}";
getJSON += "&apikey=" + apiKeyEmoncms + "\n";
getJSON += "Connection: close\n\n";
client.print(getJSON);
// display response from Emoncms
while (client.available())
{
Serial.write(client.read());
}
Serial.println("Data sent to Emoncms");
}
else
{
Serial.println("Connection to Emoncms failed");
}
client.stop();
}
void sendDataToEmoncmsTemp(void)
{
if (client.connect(emoncmsServer, 80))
{
String getJSON = "";
getJSON += "GET http://" + (String) emoncmsServer;
getJSON += "/input/post.json?json={Temperature:" + (String) temperature + "}";
getJSON += "&apikey=" + apiKeyEmoncms + "\n";
getJSON += "Connection: close\n\n";
client.print(getJSON);
// display response from Emoncms
while (client.available())
{
Serial.write(client.read());
}
Serial.println("Data sent to Emoncms");
}
else
{
Serial.println("Connection to Emoncms failed");
}
client.stop();
}
Hi Krzychb
first of all Merry Christmas :) i have followed your tutorial thanks for that. However I am struggling to get Humidity and temperature together. so what I have done is in sketch If I have this line ` getJSON += "/input/post.json?json={Temperature:" + (String) temperature + "}"; and of course same goes for Humidity it works fine.
I am able to get temperature readings, however when I try to combine both Temperature and Humidity I am not getting anywhere. my line of code is as follows:
` and message I got from console is Data sent to Emoncms Humidity: 45.40 Temperature: 22.60
so I should be able to see 2 feeds one for Humidity and one for temperature, but I don't. Can you suggest what I am doing wrong?
thanks :) `