Over a month ago I decided to give Cosm.com a try instead of using my own MySQL database and graphing in Python. Since this was awhile ago I don’t remember everything I did to get it working but I will post the code and libraries I am using that work. Here is a simple library to making sending to Cosm easy. http://www.netfluvia.org/layer8/?p=175 Here is the full code I am using to log the PIR sensor to Cosm, after the jump. #!/usr/bin/python#PIR LOGGING TO COSMimport RPi.GPIO as GPIOimport sysimport timeimport datetimefrom datetime import timedelta import cosmAPI_KEY=”API_KEY”FEED_ID=”FEED_ID”def writeCosm(status): pfu = cosm.PachubeFeedUpdate(FEED_ID,API_KEY) pfu.addDatapoint(“Pi”,status) pfu.buildUpdate() pfu.sendUpdate() print “Uploaded Motion data to Cosm” return ledPin = 17pirPin = 18motionCount = 0timerMin = 1 #Number of …
Quicknote: Raspberry Pi > Python > Serial (Updated)
Here is a quick note on using USB serial with Python. I hooked up a Sparkfun explorer board with a Xbee series 1. Sparkfun Xbee Explorer https://www.sparkfun.com/products/8687 First you need to install the Serial library: apt-get install python-serial The Sparkfun adapter uses FTDI so it shows up as /dev/ttyUSB0 I found this, it works really well. Simple TCP/IP bridgehttp://pyserial.sourceforge.net/examples.html#tcp-ip-serial-bridge I started with this link:http://www.doctormonk.com/2012/04/raspberry-pi-and-arduino.html I couldn’t get it to show data from the Xbee at first so I used Minicom to test:http://codeandlife.com/2012/07/29/arduino-and-raspberry-pi-serial-communication/#more-859 Somehow it started working once I saw data using Minicom. Here is the final code to test read from serial with Python [xbee_read.py] #!/usr/bin/pythonimport serialser = serial.Serial(‘/dev/ttyUSB0’, 9600)ser.open()try: while 1 : result = ser.readline() print result except KeyboardInterrupt: ser.close() …