When sending data to Domoticz via 'JSON URL's' you are actually performing a HTTP GET request to your Domoticz server.
You have to complete the whole HTTP GET request per sensor value before starting a new one.
I do it like the following with my Arduino's;
Every sensortype has it's own request function like this:
Code: Select all
// /json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP
void httpRequesttemp() {
// if there's a successful connection:
if (client.connect(server, port)) {
Serial.println("client connected sending temp value");
//Serial.println(dstemp);
client.print( "GET /json.htm?type=command¶m=udevice&idx=");
client.print(IDXtemp);
client.print("&nvalue=0&svalue=");
client.print(dstemp);
client.println( " HTTP/1.1");
client.println( "Host: 192.168.x.xxx");
client.println( "Connection: close");
client.println();
client.println();
client.stop();
//delay(requestdelay);
}
else {
Serial.println("client could not connect (DS value)");
client.stop();
}
}
You need to put that AFTER the 'void loop' part.
(So outside of the 'void loop' brackets)
Then inside the loop you add a check to see if the specific sensor interval has passed.
If so (and the value seems OK), send the specific request.
Other sensors can have different intervals. For most temperature sensors I use an interval of 1 minute.
Repeat the entire part below in the 'void loop' for every sensor.
If the interval is the same you can just add the request function for the specific sensor in the same if>interval function.
Code: Select all
// loop for DS18B20 sensor
if(millis() - lastTimetemp > intervaltemp) {
lastTimetemp = millis();
//DS readout starter
sensors.requestTemperatures();
dstemp = sensors.getTempC(thermometer);
Serial.println(dstemp);
// Only send data to Domoticz if the data is valid
// If the data read fails, the reported temp will be -127C.
// A bit cold to register that in Domoticz!
// So everything below -40C will be ignored.
if(dstemp >=-40){
httpRequesttemp();
}
else {
Serial.println("dstemp not valid! No HTTP request made.");
}
}
As soon as you are using multiple sensor types or doing other stuff on the Arduino it is important to avoid using delay().
Delay() will 'pause' the processor and in the mean time it does nothing, this will give timing issues in the long run.
If you are using DHT sensors you might skip the Adafruit library and use another one because the Adafruit library is very slow and big.
And if you use a DHT or other humidity sensor you need to calculate wet/dry/normal etc too.
Depending which ethernet controller you are using you might need some tweaking with timing and maybe an additional client.println(); here and there.