• @DamianMontero,

    no offense, but Espruino is never about waiting... no wait what ever configured will be right. In Espruino things are event driven, and at worst timer-event driven to poll / check (for) something.

    Depending your power situation and the given 5 minutes, it could well be that during the inactivity you completely disconnect from WiFi after completing the poll activity (get price), and a bit less than 5 minutes later you start all over with 1st powering the WiFi (module), then connect to the module, then connect to WiFi, and then make the request. To make sure and support retries of poll activity is successful, you start a smart - learning - timeout that triggers a retry before 5 minutes. This timeout is cleared as soon as the poll activity completes. The smartness would try to adjust - in an range of absolute min-max range to the sweet spot or range where you get 90% success rate. You also begin to built a FIFO w/ statistic data to mark the time (1st to 296 (12*24) 5-min-events per day with 0..255 two-second units of completion time... - that costs you only about 600 bytes. You can even show a graph of successes - dot or no dot (or even time (w/ shorter or longer vertical line of one to n dots). Over time you may then notice about the average connect/execute time at times of the day. I'm sure there is variations.

    To start from scratch with building up connectivity and tearing it down after completion, you save the code in disconnected, nothing active state, not even with a timeout running. All your activities are in (nested) functions that you call with the top-level function in onInit() with an interval... or better - timeout. The timeout time is calculated from the current time and the next 5 minute time point of the day. You do that to allow dynamics that come with retries,... and are needed for building statistics ( where you know when the last success was and how long it took. In other words there is also as 5 minute interval set to update the statistics. This update is independent of the rhythm of the poll activity. The statistics taking on 5 minute interval just pushes / places the last time of day with completion time into the FIFO / ring buffer since last taking the statistics.

    While you develop, you monitor with the IDE connected over BLE. Take a look at @JumJum's testing feature (enable it in Espruino Web IDE settings). It can draw you - in your IDE - multi line graphs and even write logs to file.

About

Avatar for allObjects @allObjects started