Ques 1:Has anyone found a way to get Gateway.py to start on Raspberry Pi bootup?
I was able to add it to sudo's crontab, while it starts, it does not pick up any data from Serial with Moteino connected, of course.
Ques 2: On rare occasion, Gateway.py stops recognizing any incoming events. I know this since I'm capturing console output using "sudo nohup python Gateway.py &". This means "nohup.out" gets anything being written to the console. I wrote a very simple linux bash script to track the modified date of this file. Using sudo's cron, in the event the modified date gets older than 10 mins it stops Gateway.py and starts it again (same command). While Gateway.py appears running in the list of processes, its not actually capturing any data from Serial. Same problem as above?
Any help or guidance on how others are ensuring their Gateway.py stays running on bootup and throughout would be great. If anyone has come across the "not receiving data as root" issue please let me know if you found a way to solve it.
I believe the problem is between Python and how it reads Serial within Raspberry Pi OS - and nothing to do with Moteino or Gateway.py at all.
Right, and I recall having some issues with python and pyserial but can't remember specifics since it's been a while.
At the moment, and moving forward, I am using node.js as my server since it supports web sockets in a format that is very desirable and easy to use. Also it has been running flawlessly and very stable with my Pi from the very beginning (perhaps 1 year or more already). For the sample node.js gateway and setup see this guide: http://lowpowerlab.com/garagemote/
Also there's a series of how the garage was automated using this node.js secured websockets and SSL: http://lowpowerlab.com/blog/2013/10/11/raspberrypi-home-automation-gateway-hardware-and-demo/
The complete walkthrough including all code and how to make the node.js gateway.js start upon startup is given at those links.
I've come across a related issue. -- I have a Moteino R4 USB connected and need it to simply
send 'x' over serial @ 115,200bps (for testing purposes).
- When I send 'x' from the Arduino serial monitor, it works fine (it communicates to a SwitchMote). The orange LED on the Moteino R4 USB blinks very briefly, ~20ms.
- When I send 'x' from Python, it does not work. The orange LED on the Moteino R4 USB stays on far longer, about 1,000ms.
I went so far as to look at the D0_RX and D1_RX signals with a logic analyzer, comparing the Arduino serial monitor to Python and the values sent out of the FDTI chip are the same. (See screenshot). Any ideas as to why or how this is possible? :D
(https://www.dropbox.com/s/lz9laut570u9frd/06%20Arduino%20and%20Python.png?raw=1)
Figure 1: Sending 'x' with Arduino serial monitor; Sending 'x' with Python 3.4.3
(https://www.dropbox.com/s/59djjpqiuvus03p/03-pySerial-issue.png?raw=1)
Figure 2: Traces comparing sending 'x' with Arduino and Python
EDIT: Fixed image links
Sounds like some pyserial issue.
What is the b in serial.write(b'x') ?
QuoteIn Python 3.x the strings are unicode by default. When sending data to Arduino, they have to be converted to bytes. This can be done by prefixing the string with b:
>>> ser.write(b'5') # prefix b is required for Python 3.x, optional for Python 2.x
Source: http://playground.arduino.cc/interfacing/python
---
I'd tend to say it's something with pySerial as well, but that doesn't explain how it's generating the same waveform.
Quote from: dom67911 on August 16, 2014, 12:31:05 AM
Any help or guidance on how others are ensuring their Gateway.py stays running on bootup and throughout would be great. If anyone has come across the "not receiving data as root" issue please let me know if you found a way to solve it.
Hi
A good guide i have used which seems to fit your needs is here, if you don't want to go down the node.js route.
http://www.sensorbay.com/2013/01/project-1-home-energy-monitor-with.html (http://www.sensorbay.com/2013/01/project-1-home-energy-monitor-with.html)
I'm using to log sensor data via a Moteino-USB gateway (connected to a Raspberry Pi with usb cable) into a date stamped csv file. I created my own logger.py than the one in the guide to avoid creation of daily files. Been running ok for a month or so.
Are you receiving data, if not, perhaps you don't have the correct serial port? Don't know if you have a Moteino-USB or not. I plugged and unplugged and ran dmesg to find the port. If not Moteino-USB then assume you have disabled the Serial Port Login as Felix notes in his guide.
Hope it helps.