Author Topic: PI gateway also sending data to wunderground.com  (Read 5461 times)

LukaQ

  • Sr. Member
  • ****
  • Posts: 284
  • Country: si
Re: PI gateway also sending data to wunderground.com
« Reply #15 on: October 17, 2017, 01:22:19 PM »
is the NAME_YOUR_FILE the same file name and extension as SOMENAME.sh or different?
Indeed it is, I wasn't that consistent when now showing what my file is named.

Kilo95

  • Sr. Member
  • ****
  • Posts: 328
  • Country: us
Re: PI gateway also sending data to wunderground.com
« Reply #16 on: October 17, 2017, 01:41:43 PM »
that what i thought you intended to do (keep the same gateway). ive been working on this on my smartphone. i'll wait a few days til i can look at it on my computer and will update then

Kilo95

  • Sr. Member
  • ****
  • Posts: 328
  • Country: us
Re: PI gateway also sending data to wunderground.com
« Reply #17 on: October 26, 2017, 11:24:25 AM »
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

Code: [Select]
#!/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
« Last Edit: October 26, 2017, 01:02:54 PM by Kilo95 »

hickse

  • Newbie
  • *
  • Posts: 3
Re: PI gateway also sending data to wunderground.com
« Reply #18 on: October 05, 2019, 12:26:24 PM »
Hello, Can you share your gateway.js file?  When I added the 2 lines of code
var fs = require('fs'); // reqire fileSystem node module
fs.writeFile("/home/pi/gateway/LOG_FILE", data );

to the end of the section of the gateway.js file
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};

I get the following errors in the gateway.sys.log

fs.js:133
  throw new ERR_INVALID_CALLBACK();
  ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
    at maybeCallback (fs.js:133:9)
    at Object.writeFile (fs.js:1179:14)
    at /home/pi/gateway/gateway.js:731:6
    at newArguments.(anonymous function) (/home/pi/gateway/node_modules/nedb/lib/executor.js:29:17)
    at Cursor.execFn (/home/pi/gateway/node_modules/nedb/lib/datastore.js:484:12)
    at callback (/home/pi/gateway/node_modules/nedb/lib/cursor.js:126:19)
    at /home/pi/gateway/node_modules/nedb/lib/cursor.js:193:12
    at /home/pi/gateway/node_modules/nedb/lib/datastore.js:329:14
    at Object.async.eachSeries (/home/pi/gateway/node_modules/nedb/node_modules/async/lib/async.js:130:20)
    at /home/pi/gateway/node_modules/nedb/lib/datastore.js:323:11


It also breaks my pigateway's functionality (until I remove those lines of code).

My code looks like this:
      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,
        multiGraphs:existingNode.multiGraphs,
        icon:existingNode.icon||undefined
      };
   var fs = require('fs'); // reqire fileSystem node module
   fs.writeFile("/home/pi/gateway/LOG_FILE", data );

I assume that the LOG_FILE file must be created prior to use. What type of file should the LOG_FILE be?  What file extension should it have?

Thanks much for your work on this.

LukaQ

  • Sr. Member
  • ****
  • Posts: 284
  • Country: si
Re: PI gateway also sending data to wunderground.com
« Reply #19 on: October 07, 2019, 03:18:44 PM »
Here you go:

my file is "mojlog" and has no extension, doesn't need one (it's text file, any linux program will read it, such as bash or nano and similar)
That file is created in same folder as gateway.js, make one yourself, can be empty