Posting to Sensor-cloud.com with Python for Android

sensor-cloud.com allows you to write your sensor data to the cloud and access the data from browsers anywhere in the world by you or your Facebook friends. Sensors are social too!

Learn:

  • Access sensor-cloud.com API

Requirements

  • The example program can be run from the smartphone or emulator.

Steps to Get Started

  1. Goto sensor-cloud.com and join the site using your Facebook login
  2. Goto My Configuration to generate the API Secret
  3. Download sensor-cloud2.py to your PC and add your API Key and Secret as per Step 2
  4. Move the modified sensor-cloud2.py to the smartphone or emulator
  5. Ensure you have network access as the program will write to the server at sensor-cloud.com
  6. Run the program.
  7. Your data will be available to you and your friends on www.sensor-cloud.com

sensor-cloud.py

import urllib import urllib2 import time import datetime print 'start logging' d = datetime.datetime.utcnow() url = 'http://api2.sensor-cloud.com' # add your key and secret # # lat, lng, and unit are optional # will use default if not provided # # dt is optional # will use server time if not provided values = {'key' : 'change_key', 'secret' : 'change_secret', 'sid': 'light', 'lat' : '1.347343', 'lng' : '103.775859', 'dt' : d.strftime("%Y-%m-%d %H:%M:%S"), 'val' : '100', 'unit' : 'lux' } data = urllib.urlencode(values) req = urllib2.Request(url, data) response = urllib2.urlopen(req) the_page = response.read() print the_page print "end logging"

Notes

Remember to change the API secret and key before running the program