Skip to content

Instantly share code, notes, and snippets.

@mydiemho
Last active July 26, 2017 00:12
Show Gist options
  • Save mydiemho/8f2d2e501e177110db64450d638d1b4b to your computer and use it in GitHub Desktop.
Save mydiemho/8f2d2e501e177110db64450d638d1b4b to your computer and use it in GitHub Desktop.
arduino + raspberry hack
# import serial
import requests
import time
import json
url = 'https://outlook.office.com/webhook/db2a1545-a674-485a-b5df-44171ce2238b@72f988bf-86f1-41af-91ab-2d7cd011db47/IncomingWebhook/9984b53e97594d888dfbdad5102d0bbc/3627016e-c8b7-4bf2-9614-234f99bc4d0f'
# ser = serial.Serial('/dev/ttyACM0', 9600)
# ser.flushInput()
inspiro_bot_url = "http://inspirobot.me/api?generate=true"
def get_quote():
url = requests.get(inspiro_bot_url).text
print url
return url
def make_body(temperature, moisure):
body = {
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"title": "Update from Planty McPlantFace!",
"text": "A gengle reminder that it's still alive.",
"themeColor": "005bae",
"sections": [
{
"facts": [
{
"name": "Temperature",
"value": "{} F".format(temperature)
},
{
"name": "Moisture",
"value": "{}%".format(moisure)
}
],
"images": [
{
"image": get_quote()
}
]
}
]
}
return body
headers = { 'content-type': 'application/json'}
prev_temp = 0
prev_moisture = 0
while True:
# line = ser.readline()
# print "line: {}".format(line)
# data = line.strip().split(",")
# print data
data = ['23', '23']
current_temp = int(data[0])
current_moisture = int(data[1])
moisture_diff = abs(prev_moisture - current_moisture)
if moisture_diff <= 5:
continue
prev_temp = current_temp
prev_moisture = current_moisture
payload = make_body(current_temp, current_moisture)
response = requests.post(url, data=json.dumps(payload), headers=headers)
print "post to yammer: {}".format(response)
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment