Hello,
Just in case someone had that issue. I am doing MicroPython IFTT project. When pressing “Test it” on IFTT site, i get an email with 3 values. However, if i copy the curl command to my Windows 10 command line, the trigger fires, but the data in the email are blanks.
curl -X POST -H “Content-Type: application/json” -d ‘{“value1″:”23.2″,”value2″:”22.2″,”value3″:”55.5”}’ https://maker.ifttt.com/trigger/bme280-1/with/key/xxxxxx
Tnaks,
But do you receive the email? Does the final project work? Thanks for letting me know… I’ve only tested the command directly the IFTTT website.
Yes, i do receive the email, but with blank values.
The project, however fails. I tried with ES8266. when i run i get errors. I do not have bme280 yet, so i have dummy values:
Start your code here
try:
temp = 55.0
hum = 40.0
pres = 10.0
sensor_readings = {'value1':temp,'value2':hum,'value3':pres}
print ('Sensor read:', sensor_readings)
request_headers = {'Content-Type:application/json'}
request = urequests.post('http://maker.ifttt.com/trigger/bme280-1/with/key/' + api_key, json=sensor_readings,headers=request_headers)
But when i download, i get errors with http: (no “s”):
Connection successful-ful
(‘192.168.y.z’, ‘255.255.255.0’, ‘192.168.x.x’, ‘192.168.x.x’)
Sensor read: {‘value3’: 10.0, ‘value1’: 55.0, ‘value2’: 40.0}
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<string>”, line 46, in <module>
File “<string>”, line 40, in <module>
File “urequests.py”, line 115, in post
File “urequests.py”, line 100, in request
File “urequests.py”, line 68, in request
TypeError: ‘set’ object isn’t subscriptable
if i use https: i get:
(‘192.168.y.z’, ‘255.255.255.0’, ‘192.168.x.x’, ‘192.168.x.x’)
Sensor read: {‘value3′: 10.0, ‘value1’: 55.0, ‘value2’: 40.0}
TLS buffer overflow, record size: 5143 (+5)
ssl_handshake_status: -257
Failed to read”help()” for more information.
Thanks
P.S. BTW why would the values be printed in different order than in the string above:
“Sensor read: {‘value3’: 10.0, ‘value1’: 55.0, ‘value2’: 40.0}”
To answer your questions:
- You need to connect to IFTTT with HTTP on the ESP. Please don’t modify that part of the code, otherwise it will not work.
- When it prints the sensor_readings, “the string” is not ordered {‘value3′: 10.0, ‘value1’: 55.0, ‘value2’: 40.0} because it’s actually a Python dictionary. However, that will not affect the request and it works
- The “TypeError: ‘set’ object isn’t subscriptable” error means that you’ve defined the dictionary in a wrong way. I’m not sure what’s missing from you, because on my end that dictionary works…
Thanks, Rui. It was my mistake. I used wrong syntax.
I used the syntax from IFTTT curl line: “”Content-Type: application/json”” in the code you gave .
Your code had single quotes around each item : ‘Content-Type’: ‘application/json’,
In the code i typed in, i was missing quotes: “‘Content-Type: application/json'”
As soon as i used your code i got the event fired and the 3 values in the email.
Sorry, to have bothered you with this.
Thanks again!