Skip to content

Instantly share code, notes, and snippets.

@entzik
Last active May 26, 2018 19:58
Show Gist options
  • Select an option

  • Save entzik/f08c600396e978ca5967b36bb553b237 to your computer and use it in GitHub Desktop.

Select an option

Save entzik/f08c600396e978ca5967b36bb553b237 to your computer and use it in GitHub Desktop.
Raspberry PI AM3203 to Lambda
#!/usr/bin/python
import sys
import Adafruit_DHT
import json
import urllib2
import time
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 2)
if humidity is not None and temperature is not None:
timestamp = int(time.time())
# Un-comment the line below to convert the temperature to Fahrenheit.
# temperature = temperature * 9/5.0 + 32
data = {
"id":None,
"tenant":"test",
"home":"main",
"room":"living room",
"timstamp":timestamp,
"temperature":temperature,
"humidity":humidity
}
req = urllib2.Request('https://api-gw-url.aws-region.amazonaws.com/production/ClimateMonitor')
req.add_header('Content-Type', 'application/json')
req.add_header('x-api-key', 'your-key')
response = urllib2.urlopen(req, json.dumps(data))
else:
print('Failed to get reading. Try again!')
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment