Easiest or Best way to connect Moteino to Raspberry PI?

Started by hexibot43, January 31, 2014, 11:28:34 AM

hexibot43

     I've been diligently working on connecting my Moteino to my Raspberry PI.  I'm seeing many ways to get this done....and wondered with all the people that have done this before me what is the easist and/or best way to accomplish this?

     My most recent thinking is to use PYserial and python to do the work of moving data from the Moteino to the the Mysql Database.  I was going to simply plug the Moteino into the PI via USB cable.  This way if I wanted to change any of the programming I will be able to use the PI to program it.  I've got the Arduino IDE up and running, and communicating with the Moteino already.  Then I can use PHP to do the work on the database, and webpages.  How does this sound?  I've got more (not much) experience with Python that PHP.  Could I do the work with PHP, including updating the Database?  I'm very green on PHP and what it can do. 

     I think my lack of familiarity with PHP is stopping me.  Any good tutorials on grabbing data from serial connection, pushing it into database, and then displaying that data in the form of webpages?

Felix

PHP is a web server side scripting language. Im not sure if there's a package for it to access the serial port on the machine it runs on.
I would much rather go with Python doing the hard work and let PHP serve the dynamic content of your web pages.
Python has a plethora of packages and it can do serial, mysql, or call URLs on the same machine. I used python to load my Moteino sensor data into EMONCMS which was running on a LAMP stack.
The connection to PI sounds good to me...

schulz

I use a moteino USB plugged into the pi, then pySerial to read from that.  It's pretty simple:

import serial
import sys
import datetime

ser = serial.Serial('/dev/ttyUSB0', 115200, xonxoff=True)

print "Starting at: "+str(datetime.datetime.now())

while True:
   try:
      sys.stdout.write(str(datetime.datetime.now()));
      sys.stdout.write("|");
      sys.stdout.write(ser.readline())
   except KeyboardInterrupt:
      break;

print "Stopped by User @ "+str(datetime.datetime.now());


Import bit is that xonxoff=True bit in the connection.  In my experience without the serial connection to the pi is flakey.

If it were me I'd use python to push into the DB and then whatever you wanted to do a web based UI after that.  If you're already comfortable in python try django.

KanyonKris

Quote from: schulz on January 31, 2014, 12:11:30 PM
If it were me I'd use python to push into the DB and then whatever you wanted to do a web based UI after that.  If you're already comfortable in python try django.

django is good, but it's a big, full web system. If you want something smaller, I've done my web front end in web.py and found it to be lightweight yet gives me all the features I want. Currently I'm using web.py to serve Jquery Mobile pages and it works fine.

hexibot43

Thanks for the input everyone.  I will continue on the path of Python.  Going to give the code shared by shultz a try.  Hoping it will jump start me....because I was good until I had to create this interface.  Moteinos all going very well.  Real stable data wirelessly.  Been trying to get my daughter to help with the web interface...but she is too busy in school. 

KanyonKris

I hear you, I've been working on a web UI and it's soaked up a lot of time figuring it out and debugging it, but I think I'm getting a little better at it. I'm doing the web UI for a project, but once I have it done I'll slim it down to a simpler more generic example application and post it. If all goes well it will support wireless programming - just click an Upload Sketch button, select a hex file and the ID of the target Moteino and away it goes.

For another example, see Felix's wireless programming Python interface program - https://github.com/LowPowerLab/WirelessProgramming/blob/master/WirelessProgramming.py

hexibot43

Ok one more stupid question....

Passing variable between the PI and the Moteino - Is it just easier to send them in ASCII delineated by commas? I'm currently just passing four floating point numbers.  The Type Struct worked great between Moteinos, but I'm worried of format irregularities between Moteino coded floats and Python.  I honestly have no idea how the Float is coded. 

Thank you Shultz!  I've got my Gateway Moteino talking to my Python coded PI.  Just passing ASCII at the moment.  But that got me going again.  The rest will just fall together.   

Felix

My take is that it's easier to pass ASCII from the Moteino. Also more transparent when you ever need to look at the data. Python will easily cast it to a real float.

mzv72m

For those looking for PHP and other web tools tutorials www.w3schools.com has a lot of good info.  It is great for reference when you need to do something and not sure how to do it.
Dan

cootcraig

Quote from: KanyonKris on January 31, 2014, 01:33:54 PM
I've done my web front end in web.py and found it to be lightweight yet gives me all the features I want. Currently I'm using web.py to serve Jquery Mobile pages and it works fine.
web.py looks good, I'll keep it mind for future projects.

KanyonKris

Quote from: cootcraig on March 22, 2014, 12:33:00 AM
Quote from: KanyonKris on January 31, 2014, 01:33:54 PM
I've done my web front end in web.py and found it to be lightweight yet gives me all the features I want. Currently I'm using web.py to serve Jquery Mobile pages and it works fine.
web.py looks good, I'll keep it mind for future projects.
Also consider Flask instead of web.py as it's a newer framework a Python expert recommended to me.