LowPowerLab Forum

Software support => Pi Gateway => Topic started by: Uncle Buzz on February 13, 2020, 03:20:34 AM

Title: Is it possible to add nodes from internet ?
Post by: Uncle Buzz on February 13, 2020, 03:20:34 AM
Hi,
I wonder if it's possible to have a pi gateway at home, with some local nodes, and to receive on the same server some data from nodes on other areas, with internet transmission instead of serial transmission from the local RF gateway ?

For example, I would like to have a PI with 4G connection and a moteino gateway who would collect some local nodes data, then send these data through the 4G connection to the PI gateway at home so I could see them like any other local nodes on the same server ?

I saw on the TODO list the line
Quoteallow tokenized REST/HTTP requests from wifi/lan/internet nodes - done in v9.0

Does it mean that I could achieve what I want since v9.0 ?

Could we configure a PI gateway to transmit the local data to a remote server ?
Title: Re: Is it possible to add nodes from internet ?
Post by: Felix on February 13, 2020, 10:24:32 AM
Yes support for posting data via an HTTP endpoint was implemented in 9.0. This could be from anywhere or anything that can make a HTTP request to your PiGateway.
You will however need to write the events or actions that will make these calls to another PiGateway install.

Basically what you need to make HTTP call with your data to the desired node, and also include HTTP_AUTH. A call using the already included request module (see how tstatpoll uses it in metrics.js) would simply look like:

request.get('https://IP_or_hostname_where_other_PiGateway_lives/httpendpoint/?id=1234&MOTION&F=77.77').auth('username', 'password', false);

Where 1234 is the node ID to post the data to, and example metrics are:
- MOTION  (simply report motion NOW - ie at current timestamp)
- F=77.77  (report temperature in F is now 77.77)

More details on using request are here: https://github.com/request/request#http-authentication
Title: Re: Is it possible to add nodes from internet ?
Post by: Uncle Buzz on February 13, 2020, 12:13:20 PM
So if I use a PI gateway on another area, and I want to send all data to another one, I have to add an event on my first PI gateway to send an http request with the new data to the "main" PI gateway ? I just need to convert serial message from the moteino gateway to equivalent http request?
Title: Re: Is it possible to add nodes from internet ?
Post by: Felix on February 13, 2020, 06:01:45 PM
You're not locked into doing it one way.
You decide what data you want to send and when.
You could just inject some code to handle http requests for every valid data received, at the beginning of handleSerial

Just take a look at processSerialData and httpEndPointHandler, they are somewhat similar.
You could simply take the serial message and pass it on to the other Pi and do nothing else, or continue parsing and adding it locally as well.
Or you could create events based on some condition and only pass data then. Whatever.
Title: Re: Is it possible to add nodes from internet ?
Post by: Uncle Buzz on March 08, 2020, 06:04:15 AM
Well, since my distant nodes and PI will be off the grid, the PI consumes too much energy and it's a big thing for just transferring some POST requests...

I think a sms gateway based on a moteino + something like SIM800L GSM modem on both side will be sufficient and low power next to the PI solution... It would be also cheaper to buy, and to use since no DATA plan is needed to send some SMS...