User Tools

Site Tools


add_temperature_sensor_in_domoticz

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
add_temperature_sensor_in_domoticz [2016/04/03 22:06]
sgripon [Reference]
add_temperature_sensor_in_domoticz [2016/11/11 20:01] (current)
sgripon [Reference]
Line 17: Line 17:
 I modified a little bit the previous sketch in order to read from the serial line and send the temperature only when it is requested by client. I modified a little bit the previous sketch in order to read from the serial line and send the temperature only when it is requested by client.
  
-<code C++>+<file C++ SmartHomeBox_sgripon.ino>
 #include <​RFControl.h>​ #include <​RFControl.h>​
  
Line 110: Line 110:
   ​   ​
 } }
-</code>+</file>
  
 ==== The Auto-reset issue ==== ==== The Auto-reset issue ====
Line 140: Line 140:
 This is the source code of my own script. The script reads the temperature value by asking the arduino to write the value to the serial line. The script use an external library to decode JSON data (see http://​regex.info/​blog/​lua/​json). This is the source code of my own script. The script reads the temperature value by asking the arduino to write the value to the serial line. The script use an external library to decode JSON data (see http://​regex.info/​blog/​lua/​json).
  
-<code lua>+<file lua script_time_HardwareName.lua>
 -- Serial port must be configured before opening the file -- Serial port must be configured before opening the file
 -- stty -F /​dev/​ttyACM0 9600 -- stty -F /​dev/​ttyACM0 9600
Line 156: Line 156:
  
 -- Because Arduino auto-reset when a serial line is open, wait the end of reset before doing anything -- Because Arduino auto-reset when a serial line is open, wait the end of reset before doing anything
-os.execute("​sleep ​" .. tonumber(2))+os.execute("​sleep 2")
  
 -- First send a command to read the temperature. -- First send a command to read the temperature.
Line 171: Line 171:
  
 -- Ask a new read until a signal has been received from the sensor. It should be available within next 30 seconds with this sensor. -- Ask a new read until a signal has been received from the sensor. It should be available within next 30 seconds with this sensor.
 +local nbTries = 0;
 local json_value = JSON:​decode(read_value) local json_value = JSON:​decode(read_value)
-while json_value.channel==0 do+while json_value.channel==0 ​and nbTries < 16 do 
 + nbTries = nbTries + 1 
 + os.execute("​sleep 2")
  wserial:​write("​r"​)  wserial:​write("​r"​)
  wserial:​flush()  wserial:​flush()
Line 179: Line 182:
 end end
  
--- Update the sensor value with the new temperature +-- Update the sensor value with the new temperature ​if a temperature has been read 
-commandArray['​UpdateDevice'​]=deviceNum..'​|0|'​..json_value.temp/​10+if json_value.channel==1 then 
 + commandArray['​UpdateDevice'​]=deviceNum..'​|0|'​..json_value.temp/​10 
 + -- print("​[DEBUG] Temperature:​ "​..json_value.temp) 
 +end
  
 return commandArray return commandArray
-</code>+</file>
 ===== The Temperature dashboard ===== ===== The Temperature dashboard =====
  
 {{ ::​domoticz-temperature.png |}} {{ ::​domoticz-temperature.png |}}
 +
 +===== See also =====
 +  * [[add_temperature_and_humidity_sensor_dht11_in_domoticz|Add temperature and humidity sensor DHT11 in Domoticz]]
 +  * [[record_temperature_from_lexibook_asm30_sensor|Record temperature from Lexibook ASM30 sensor with Arduino]]
  
 ===== Reference ===== ===== Reference =====
Line 192: Line 202:
   * Domoticz: https://​www.domoticz.com/​   * Domoticz: https://​www.domoticz.com/​
   * Arduino: Disabling Auto Reset On Serial Connection : http://​playground.arduino.cc/​Main/​DisablingAutoResetOnSerialConnection   * Arduino: Disabling Auto Reset On Serial Connection : http://​playground.arduino.cc/​Main/​DisablingAutoResetOnSerialConnection
-  * JSON encoding/​decoding in LUA: http://​regex.info/​blog/​lua/​json+  * JSON encoding/​decoding in LUA by Jeffrey Friedl: http://​regex.info/​blog/​lua/​json
  
 **Share this page:** **Share this page:**
  
 ~~socialite~~ ~~socialite~~
add_temperature_sensor_in_domoticz.1459713965.txt.gz · Last modified: 2016/04/03 22:06 by sgripon