Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temperature problem #8

Open
xxvms opened this issue Dec 23, 2016 · 2 comments
Open

Temperature problem #8

xxvms opened this issue Dec 23, 2016 · 2 comments

Comments

@xxvms
Copy link

xxvms commented Dec 23, 2016

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:

  `getJSON += "/input/post.json?json={Humidity:" + (String) humidity +", Temperature:" + (String) temperature +"}";

`
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 :)
`

@krzychb
Copy link
Owner

krzychb commented Dec 23, 2016

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

@krzychb krzychb mentioned this issue Dec 23, 2016
@xxvms
Copy link
Author

xxvms commented Dec 23, 2016

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants