Cloud Connected Temperature Sensor
measure temperature, upload temperature, wait a few moments, do it again, with scriptingWork in progres...
This note consists of the following steps:
- Prerequirements
- Preparing Linux host
- Software installation
- Scripting
Prerequirements
Some kind of cloud service is obviously needed. It should provide at least a method through it receives data.
For this application note a cloud service 4floats.com was established. It supports widely used protocols, namely HTTP and HTTPS, with GET and POST methods. Once the value is sent, it could be obtained.
Preparing Linux host
See section of the same title of related application node. At this point you should have a USB temperature probe accessible and working.
Software installation
Software section depends on chosen cloud service. For 4floats.com only a HTTP client, e.g. curl or wget, is needed. In this application note, wget will be used, so install it by sudo apt-get install -y wget
.
Scripting
Manual check
Before going to automation, commands need to be ran one by one while checking performance, return values etc.
The following command accesses USB thermometer on /dev/ttyUSB0
and return just a value in degrees Celsius.
utmp-cli -q -s /dev/ttyUSB0 | cut -d" " -f6
The same output could be achived with digitemp, but first a digitemp configuration, /etc/digitemp.conf
must be created.
digitemp_DS9097 -q -c /etc/digitemp.conf -t 0 | cut -d" " -f7
Next step is sending this value (output) to the cloud service. For 4floats.com we choice arbitrary channel name and key with regard to limits stated on the website. For this application note, as an example, channel name is appnote with its key 2025utmp. We send value of 20
to float key t
, t as an abbreviation for temperature.
wget -q "https://a.4floats.com/poke/appnote?key=2025utmp&t=20" -O -
On success a {"error":"None"}
will be returned. Then the value sent could be obtained by:
wget -q "https://a.4floats.com/peek/appnote" -O -
On success something like {"t":"20","timestamp":"1735689600000"}
will be returned.
Automation
The following script uploads temperature from device connected to /dev/ttyUSB0 to channel appnote protected with key 2025utmp to float key t using utmp-cli and wget.
SERVER="http://49.13.30.209" # resolved IP for a.4floats.com CHANNEL=appnote KEY=2025utmp SERIAL_PORT=/dev/ttyUSB0 test -c "$SERIAL_PORT" || exit 2 NAME=$(basename $0 | cut -d. -f1) LOG_FILE="/tmp/$NAME" TEMP_C=$(utmp-cli -q -s $SERIAL_PORT | cut -d" " -f6) if [ $? -eq 0 ]; then wget --post-data "t=${TEMP_C}&key=${KEY}" "$SERVER/poke/$CHANNEL" \ -O "${LOG_FILE}-output" >"${LOG_FILE}-wget" 2>&1 fi
Save upper script to a file, e.g. /home/yourusername/upload.sh
and make it executable by chmod u+x /home/yourusername/upload.sh
.
Now execute your script by /home/yourusername/upload.sh
and take a look into files /tmp/upload-output
and /tmp/upload-wget
. The content of output should be like {"t":"20","timestamp":"1735689600000"}
.
Troubleshooting
Write to support e-mail address on main website. Your e-mail will improve content and clarity.