I really don’t want to buy an expensive and boring weather station, so I decided to connect DS18B20 that costs $6 in a local hardware store.
root@raspbian:/t# cat gettemp
temp=$(cat /sys/bus/w1/devices/28-*/w1_slave | grep -E -o ".{0,0}t=.{0,5}" | cut -c 3-)
temp=$(echo "scale=3; $temp/1000" | bc)
echo $temp > /t/curtemp
Run["/t/gettemp"];
<< "/t/curtemp"
And it works… But the problem is that ti works extremely slow…
It takes about one second to acquire the temperature from bash and about 20 seconds to do it from Wolfram. The other interesting thing is that the more the delay between executions of the cell, the less the duration of measurement. The first execution lasts about 2 seconds. And it seems like the standby time before execution can compensate the execution time. If standby time was 10 seconds, the execution lasts 10 seconds.
Very interesting yet very useless feature… My aim is a dynamic plot of temperature, updating every second, buy it seems like I’m following the wrong path…
I need to read bash output, it can be faster, but I don’t know how…
There’s one thing that can probably help
In[40]:= FindDevices[]
Out[40]= {DeviceObject[{"DefaultShellCommandDemo", 3}], DeviceObject[{
"DelayedRandomSignalDemo", 3}], DeviceObject[{
"GPIO", 4}], DeviceObject[{"RandomSignalDemo", 1}], DeviceObject[{
"RaspberryPiWeatherStation", 3}], DeviceObject[{
"RaspiCam", 3}], DeviceObject[{
"ShellCommandDemo", 1}], DeviceObject[{
"TinkerForgeWeatherStation", 3}]}
I like the DeviceObject[{“ShellCommandDemo”, 1}], but attemps to read from it failed.
Any ideas?
--- UPD ---
For now, I’ve made a data-collecting script, that collects data with maximum speed and stores it in Mathematica-friendly file.
file=/t/templog
trap ctrl_c INT
function ctrl_c() {
echo
echo Please, the last one...
temp=$(cat /sys/bus/w1/devices/28-*/w1_slave | grep -E -o ".{0,0}t=.{0,5}" | cut -c 3-)
temp=$(echo "scale=3; $temp/1000" | bc)
now=$(date +%s.%3N)
rel=$(echo "scale=3; $now-$start" | bc)
echo \{$rel,$temp\}
echo \{$rel,$temp\}\}\; >> $file
echo Print[\"data is stored in TempData variavle\"] >> $file
exit $?
}
echo \(\* $(date) \*\) > $file
echo TempData={ >> $file
start=$(date +%s.%3N)
for (( ; ; ))
do
temp=$(cat /sys/bus/w1/devices/28-*/w1_slave | grep -E -o ".{0,0}t=.{0,5}" | cut -c 3-)
temp=$(echo "scale=3; $temp/1000" | bc)
now=$(date +%s.%3N)
rel=$(echo "scale=3; $now-$start" | bc)
echo \{$rel,$temp\},
echo \{$rel,$temp\}, >> $file
done
The output can be used, for example, for plot
In[40]:= << "/t/templog"
Out[40]= data is stored in TempData variavle
In[41]:=ListLinePlot[TempData]



