Dear all,
I am trying to create a smart thermostat using arduino and ubidots.
Several sensors are connected to my arduino + ethernet shield: temperature, humidity and light.
I would like to send this sensor data to ubidots. at the same time I would like to control my thermostat from the cloud using an on/off switch and a slider to set the desired temperature.
If the switch is in ON state and the temperature is lower than the desired the arduino will activate an electric heater.
sending the sensor data (light, humidity, temperature) works fine. and also getting the control inputs from ubidots (switch + desired temperature) works fine seperatly. when combining both in my main arduino loop, it doesn’t work anymore.
plaese find my code below:
void getData()
{
// get data from cloud
enabled = client.getValue(ID_enable);
temperature_control = client.getValue(ID_temperature_control);
}
void sendData()
{
// send data to cloud
client.add(ID_temperature, temperature);
client.add(ID_humidity, humidity);
client.add(ID_light, light);
client.sendAll();
}
void logData()
{
Serial.println();
Serial.print("temperature: “);
Serial.print(temperature);
Serial.print(” / humidity: “);
Serial.print(humidity);
Serial.print(” / light: “);
Serial.print(light);
Serial.print(” / enabled: “);
Serial.print(enabled);
Serial.print(” / temperature control: ");
Serial.println(temperature_control);
}
void loop()
{
// update senor values
thermostat.update();
state = thermostat.state;
humidity = thermostat.humidity;
temperature = thermostat.temperature;
light = thermostat.light;
// get cloud data
getData();
// log sensor and cloud data
logData();
// send data to the cloud
sendData();
delay(2000);
}
In my serial window I get the output below.
the variables enabled and temperature control are always 0.00.
They are however correctly send through in the json as can be seen (0.00 and 18.00 respectively).
Can anybody help with this?
Geting your variable
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 29 Dec 2016 17:59:06 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept, Cookie
Allow: GET, POST, HEAD, OPTIONS
148
{“count”: 28, “next”: “http://things.ubidots.com/api/v1.6/variables//values?page=2&page_size=1", “previous”: null, “results”: [{“url”: "http://things.ubidots.com/api/v1.6/values/”, “value”: 0.0, “timestamp”: 1483026323§Î
Geting your variable
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 29 Dec 2016 17:59:07 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept, Cookie
Allow: GET, POST, HEAD, OPTIONS
149
{“count”: 33, “next”: “http://things.ubidots.com/api/v1.6/variables//values?page=2&page_size=1", “previous”: null, “results”: [{“url”: "http://things.ubidots.com/api/v1.6/values/”, "value": 18.0, “timestamp”: 148302432
temperature: 13.00 / humidity: 48.00 / light: 7.00 / enabled: 0.00 / temperature control: 0.00
Posting your variables
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 29 Dec 2016 17:59:09 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept, Cookie
Allow: POST, OPTIONS
42
[{“status_code”: 201}, {“status_code”: 201}, {“status_code”: 201}]
0