BigSnarf blog

Infosec FTW

Arduino Sensor, Python, and Google Analytics

_DSC0333

Screen Shot 2013-12-21 at 8.14.56 PM

Screen Shot 2013-12-21 at 8.19.16 PM

import serial
import time
import urllib2
import urllib
import httplib
ser = serial.Serial('/dev/tty.usbserial-AM01VDMD')
print ( "connected to: " + ser.portstr )
buf = []
while True:
 for line in ser.read():
 buf.append(line)
 if line == "\n":
 result = "".join(buf).strip()
 print result
connection = httplib.HTTPConnection('www.google-analytics.com')
 params = urllib.urlencode({
 'v': 1,
 'tid': 'UA-46669546-1',
 'cid': '555',
 't': 'event',
 'ec': 'arduino',
 'ea': 'ldr',
 'ev': result
 })
 connection.request('POST', '/collect', params)
 print "Posted to GA"
 print params
 buf=[]
ser.close()
"""
const int ledPin = 13;
const int sensorPin = 0;
void setup() {
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
}
void loop() {
 int rate = analogRead(A0);
 digitalWrite(ledPin, HIGH); 
 delay(rate); 

 digitalWrite(ledPin, LOW); 
 delay(rate);

 Serial.println(rate);
 delay(500); //slow down the output for easier reading
}
"""

Motitvation http://www.forbes.com/sites/ericsavitz/2013/01/14/ces-2013-the-break-out-year-for-the-internet-of-things/

https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-7-reading-a-temperature-sensor

3 responses to “Arduino Sensor, Python, and Google Analytics

  1. Pingback: Arduino Laser Trip Wire with Analytics | CL-UAT

  2. Pingback: Arduino Laser Trip Wire with Analytics | DL-UAT

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: