Does anyone have sample code on how RasPi (Gateway.py maybe) send a command instead of just receiving them?
My goal is for Gateway.py to poll an external website and based on some value (ex: ON) to then send a message to a "node" Moteino and perform some action (ex: turn on LED). I'm drawing a blank on how to do this.
So, typically, this is the setup:
"sender" Moteino sensor -> data to "receiver" Moteino -> connected to RasPi
In my case I'd like:
Gateway RasPi polls website until "ON" -> sends "some message" -> "receiver" ??? -> RF message to "sender" ??? (with receiver sketch loaded)
Thinking a bit further, maybe I cannot reuse the same "receiver" Moteino in this case.
Instead, a second Moteino connected to a RasPi GPIO pin. If so, then the end result would be 1 RasPi with 2 Moteinos
- one for receiving data as normal
- one for sending data.
-- if this is true, then sending data to multiple Moteinos FROM RasPi may require individual connections from RasPi GPIO pins to select Moteino PINs. Sound right?
I guess I could draw this out, but figure I'd start here in case anyone has done something similar.
In reality, my project is to have a webpage where I can set a value to "NOW" - mobile friendly.
The RasPi Gateway would poll that site until "NOW" is encountered and power-off and on my router at home. For this case, I'm not going to get into the specifics on how to remove the "NOW" value on the page. A simple HTTP POST and PHP page should work, but that's not the goal of my question.
I'm not quite clear why you need a Moteino. I'm going to assume that you want to locate one Moteino at your router, which is far from your Pi. Otherwise, you could do this easily without the RF component.
What it sounds like you need is the following:
1. RasPi reads internet data
2. Raspi sends command to local Moteino
3. Local Moteino sends command to remote Moteino
4. Remote Moteino does something
This is not hard. I'll assume you can hand #s 1 and 4.
#2 happens over serial. You need to take the normal steps on a Pi to disable the console on TTYAMA0 so that you can use it to communicate with the Moteino, and connect the TX/RX pins.
#3 happens over RF. You can send with the SendWithRetry function, as demonstrated in the sample sketches, making sure your network, destination, and source IDs line up correctly.
The rest is simply a matter of getting your Moteinos to read and interpret commands, from the Pi over serial, and then from one Moteino from another.
Drop some more details on where you're stuck, or if I'm missing what you're asking.
Colin
Oh, and there's loads of Moteino Raspi code around, but here is an example:
https://github.com/iinnovations/iicontrollibs/blob/master/mote/serialhandler.py
See write() and monitor() functions there
Colin
Yes, you answered my biggest question. So a local Moteino is needed. Thanks!
You're right, I could just use a RasPi for this, but then I would not have learned how to have RasPi send a msg to a distant node. Besides, I like the decoupling and using a less expensive approach. Once I learn this then I can start working on a swarm of Moteinos performing tasks I dictate over the web.
This should be enough to get me started. Thanks again!
No problem.
I would, however, strongly encourage you to consider using a RasPi as an air traffic controller and web server. It's really much better built for it than a microcontroller.
C