I will first start with this: I don't know how to do that.
That being said, you could use, like your said, invoke a HTTP request to their API to post the data, like you can do with browser or you could used
https://www.npmjs.com/package/wunderground-pws
But first problem for me is, how to get data from serial and not disturb gateway itself.
-This could be like stream, just like gateway does it with serial.on("data", function(data) { processSerialData(data); });
-Or if that would be written to a file, which would be read with other program, which would open file and read it, then send to WU.
-Or extract data from: var entry = {_id:id, updated:existingNode.updated, type:existingNode.type||undefined, label:existingNode.label||undefined, descr:existingNode.descr||undefined, hidden:existingNode.hidden||undefined, rssi:existingNode.rssi, metrics:Object.keys(existingNode.metrics).length > 0 ? existingNode.metrics : {}, events: existingNode.events, settings: existingNode.settings };
and put them in each variable, then invoke a HTTP request with variables in the URL
Also don't know if I would like to go with already parsed data, which gateway uses or raw data from serial port itself
Saving serial to file can be done like so:
var fs = require('fs'); // reqire fileSystem node module
fs.writeFile("/home/pi/gateway/name_of_your_file", data );
writeFile will overwrite file, you could append with , but I don't see it being useful just yet
From file I read:
[40] C:23.04 H:50.67 P:1022.08 [RSSI:-54][ACK-sent]
and I can extract C: number only with
less -FX /home/pi/gateway/name_of_your_file | awk '{print $2}' | sed -e 's/C://'
and get only
Success!!!
Now I can send from gateway to wunderground.com
Now how to do it:
1)you will need bash calculator 2)you will need to add var fs = require('fs'); // reqire fileSystem node module
fs.writeFile("/home/pi/gateway/LOG_FILE", data );
to gateway.js, right after var entry = {_id:id, updated:existingNode.updated, type:existingNode.type||undefined, label:existingNode.label||undefined, descr:existingNode.descr||undefined, hidden:existingNode.hidden||undefined, rssi:existingNode.rssi, metrics:Object.keys(existingNode.metrics).length > 0 ? existingNode.metrics : {}, events: existingNode.events, settings: existingNode.settings};
By now you will have ability to calculate float in bash and you will be write "data" (which is what serial gets) to file (append/overwrite).
3)After that, you will need bash script: nano SCRIPT_NAME.sh
#!/bin/bash
while :
do
var="$(less -FX /home/pi/gateway/LOG_FILE | awk '{print $1}' )"
echo $var
if [ "$var" == "[5]" ]
then
temp1="$(less -FX /home/pi/gateway/LOG_FILE | awk '{print $2}' | sed -e 's/C://')"
temp=$(echo "$temp1*1.8+32" | bc)
fi
###########################################################################################################################################################################################################################################
if [ "$var" == "[40]" ]
then
humidity1="$(less -FX /home/pi/gateway/LOG_FILE | awk '{print $3}' | sed -e 's/H://')"
pressure1="$(less -FX /home/pi/gateway/LOG_FILE | awk '{print $4}' | sed -e 's/P://')"
humidity=$(echo $humidity1/1 | bc)
baro=$(echo "scale=2;$pressure1/33.863753" | bc)
fi
###########################################################################################################################################################################################################################################
echo $temp
echo $humidity
echo $baro
curl "https://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=YOURSTATIONNAME&PASSWORD=YOURPASSWORD&dateutc=now&tempf=${temp%$cr}&baromin=${baro%$cr}&humidity=${humidity%$cr}&weather=&clouds=&softwaretype=Arduino-ESP8266&action=updateraw"
sleep 10
done
run ./SCRIPT_NAME.sh
if you are in the same folder as SCRIPT_NAME.sh, else enter full path
Oh and BTW, I do calculations because I have °C, and mBar and not °F and inHg, which site expects.
Have fun
Note: Have changed the two files names, so that is more clear which is which, since they are both in the same folder
wonderful! thanks for your hard work. i do have one additional question...I have 4 nodes on one gateway. how can i send the data from just one particular node to WU by this route and leave the rest as is? it'd be node 5
I have two nodes, 5 and 40. From one I take temp, from other I take pressure and humidity. If you have more nodes you just add more IF cases, each looking for specific node number you have.
One thing would also be to optimize this script, for it to collect all different data over longer time, then send once, not everytime node is read.
You can comment out IF node == 40, and move what is in IF statement into IF statement of node 5
while :
do
var="$(less -FX /home/pi/gateway/mojlog | awk '{print $1}' )"
echo $var
if [ "$var" == "[5]" ]
then
temp1="$(less -FX /home/pi/gateway/mojlog | awk '{print $2}' | sed -e 's/C://')"
temp=$(echo "$temp1*1.8+32" | bc)
humidity1="$(less -FX /home/pi/gateway/mojlog | awk '{print $3}' | sed -e 's/H://')"
pressure1="$(less -FX /home/pi/gateway/mojlog | awk '{print $4}' | sed -e 's/P://')"
humidity=$(echo $humidity1/1 | bc)
baro=$(echo "scale=2;$pressure1/33.863753" | bc)
fi
echo $temp
echo $humidity
echo $baro
curl "https://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=XXXXXX&PASSWORD=XXXXX&dateutc=now&tempf=${temp%$cr}&baromin=${baro%$cr}&humidity=${humidity%$cr}&weather=&clouds=&softwaretype=Arduino-ESP8266&action=updateraw"
sleep 10
done
this will read all 3 variables from node 5. As if you had BME280 there
Now to make it autorun on startup you need to do:
then before end of the file, before exit 0 you add
/path/to/my/SCRIPT_NAME.sh || exit 1 # Added by me
then you save and can reboot
This will start a process under root, which will run this script.
And this should be all you need to send any data WU accepts.
Note: Changed the script name
Luka, just wanted to post what finally worked for me that you helped me work out off forum.
1. Made sure the permissions for the "WHATEVERNAME.sh" was set to 744 or 777.
2. Removed the conversions to metric
3. Changed the C in the script for the temperature to F (otherwise kept giving a syntax error)
4. Changed the print function from 2,3,4 ({print $2}, {print $3}, etc) to 3,4,5 ({print $3}, {print $4}, etc) since my output from the node shows the battery voltage in the #2 slot {print 2}
5. Set var [5] and removed the reference to var [40] since all 3 of my metrics comes from one node (#5).
6. One node i have outputs temp as 4 digits (ex 5895 but on the gateway page shows up as 58.95 deg) so i divided the temp by 100. that's on a Weathershield R1. on my WS R2, it comes out as 58.95 without the correction
many thanks to Luka for his advice and help. all the credit goes to him
#!/bin/bash
while :
do
var="$(less -FX /home/pi/gateway/NAME_YOUR_FILE | awk '{print $1}' )"
echo $var
if [ "$var" == "[5]" ]
temp1="$(less -FX /home/pi/gateway/NAME_YOUR_FILE | awk '{print $3}' | sed -e 's/F://')"
temp=$(echo $temp1/100 | bc)
humidity1="$(less -FX /home/pi/gateway/NAME_YOUR_FILE | awk '{print $4}' | sed -e 's/H://')"
pressure1="$(less -FX /home/pi/gateway/NAME_YOUR_FILE | awk '{print $5}' | sed -e 's/P://')"
humidity=$(echo $humidity)
baro=$(echo $pressure1)
fi
###########################################################################################################################################################################################################################################
echo $temp
echo $humidity
echo $baro
curl "https://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=YOURSTATIONNAME&PASSWORD=YOURSTATIONKEY&dateutc=now&tempf=${temp%$cr}&baromin=${baro%$cr}&humidity=${humidity%$cr}&weather=&clouds=&softwaretype=Arduino-ESP8266&action=updateraw"
sleep 10
done