Callback help #708
Replies: 11 comments
-
Posted at 2017-03-22 by @gfwilliams How about changing your existing callback:
to:
So now you send the form as soon as you have the information ready? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-22 by countxerox Great, thanks Gordon |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-22 by countxerox Hi, I'm trying to add a BH1750 sensor to measure light intensity but now when I send the form, after one succesfull send, I get errors...
but it seems like there is enough memory. I don't understand what I've done wrong.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-22 by oesterle I'd try breaking
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-22 by countxerox Thanks @oesterle, it worked a treat. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-22 by oesterle Wow. OK, then! Sorta cool when you code something up, and it runs on someone else's hardware the first time. Cheers, @countxerox. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-26 by countxerox Hi, I let the program run for 25 hrs, sending to google every 2 minutes but when I look at google for the responses only 417 responses have been logged. It didn't crash but after the first few successful sends it either has the memory error, handshake failed or it works.
Is there something wrong with my code again?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-26 by oesterle Right now, everything lives inside I'd try to make You also have a long-lived nest of multiple callback functions. I'd pull the connection and sending out into a separate function that's called every 2 minutes. In that function, I'd also turn off Wi-Fi when done sending. This is good practice for IoT sensors that you intend to battery power, also. Finally, you'll still probably have rare occasions where connection or sending fails, but these should be less frequent. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-27 by countxerox Thanks for that advice @oesterle. I've had a go and I think it's improved but I can't close the wifi connection. wifi.disconnect() isn't recognised.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-28 by oesterle That code looks a lot cleaner, @countxerox!
Well, at least it's perfectly OK to call I wonder why |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-28 by @gfwilliams There actually isn't a disconnect function in the ESP8266_WiFi driver - there's just what is mentioned here: http://www.espruino.com/ESP8266#reference If you want to disconnect to save power, I'd recommend that you actually bring the CH_PD wire out from the ESP8266 and connect it to Espruino - you can then totally power the chip down, which should be a lot more efficient than just telling it to disconnect from WiFi. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-22 by countxerox
Hi, I'm writing some code for my Pico with an ESP8266 which sends temperature and humidity sensor readings to a Google Form (like this tutorial).
I'm using a DHT11 sensor like this...
Then next I send the Temp and Humidity to Google like this...
but the sensor hasn't finished reading yet, it's to soon to send the data. I can use setTimeout to wait a couple of seconds before sending, that works, but I'm thinking I need learn how to use a callback but I can't work out how to write it.
Beta Was this translation helpful? Give feedback.
All reactions