Notifications
Clear all

Arduino IoT Cloud Question

17 Posts
3 Users
3 Likes
1,926 Views
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

I have an Arduino IoT Cloud question. I have a ESP32-Pico-D4 installed in a rabbit shed. The Pico takes input from a temp sensor and turns on/off fans, heat lamps, or water heaters based on the temperature. The Pico has been working perfectly. I connected the Pico to the Arduino IoT Cloud so my wife can check the temperature in the shed from her phone and override the Pico’s control of the fans, lamps, or water heaters (off to on or on to off) if she desires.

The problem I am having is that the Pico is dropping the connection to the cloud. I have to go into the shed and reset the Pico. I would like to add a status check in the loop function to see if the connection is ‘up’ and reestablish the connection if necessary.

I tried to search for the commands but couldn’t find any documentation (may be asking the wrong question to google).

In the thingProperties.h file is the command:

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Which I am assuming initiates the initial connection to the Arduino cloud.

In the setup function is the command:

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

Then in the loop function is the command:

ArduinoCloud.update();

 

I can’t find what operations these functions perform or the list of options for the ‘ArduinoCloud’ command.

 

Any assistance would be greatly appreciated.

 

Mike


   
Quote
Topic Tags
b
 b
(@b)
Noble Member
Joined: 4 years ago
Posts: 912
 

@huckohio

Maybe you need an watchdog circuit that can re-boot your board if it goes down.

The video link below may be of interest.


   
ReplyQuote
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

Here is a re-post that is easier to read.

I have an Arduino IoT Cloud question.  

I have an ESP32-PICO-D4 installed in a rabbit shed that takes input from a temperature sensor and then turns on/off fans, heat lamps, or water heaters as necessary.  I connected the PICO to the Arduino IoT Cloud so my wife can check the temperature on her phone and choose to override the current state of the fans, heat lamps, or water heaters. 

The PICO is working without issue.  The problem is the PICO drops connection to the Arduino IoT Cloud.  I have to go into the shed to reset the PICO to re-establish the connection.  I would like to add a status check into the Loop function that will check the connection and re-connect if necessary.  

I have been unable to find any examples/commands on how to check connection status.  In the thingProperties.h file (this file is automatically created when you make an Arduino IoT Cloud project) there is the command:

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Which establishes the connection to the wifi.  In the main .ino file Arduino IoT Cloud adds the following command in setup:

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

Which connects to the cloud.  Then in the loop function there is the command:

ArduinoCloud.update();

I really don't know what this function performs.  

Other than these commands, I can't find any other commands that will check connection status and re-connect.  I am sure the issue is I am not looking in the right place.


   
ReplyQuote
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

@byron

Thanks.  I'll watch the video.


   
ReplyQuote
b
 b
(@b)
Noble Member
Joined: 4 years ago
Posts: 912
 

@huckohio

Thats more readable 😀.  I see that your ESP32 may not go down completely but just loose its connection to the IOT cloud.  I expect theres a better way to check on the cloud connection than this suggestion, but you could have your code regularly send and receive a value from the cloud in a similar fashion that the droneBot video showed sending and receiving pushbutton events albeit in that example he was showing 2 different boards.

In conjunction with a watchdog timer, if the expected value is not received from the IOT cloud then the pulses sent to the watchdog timer could be stopped, thus triggering your watchdog timer to reboot your ESP32.

 


   
ReplyQuote
DaveE
(@davee)
Prominent Member
Joined: 2 years ago
Posts: 787
 

Hi huckOhio,

  I suspect @byron is closer to your problem in the last message. However, a quick Google suggests that the Arduino cloud is being 'forced' down the watchdog route..... see the GitHub code Readme at https://github.com/arduino-libraries/ArduinoIoTCloud#readme

... look down to the 'FAQ' paragraph ... and for 'unrecoverable software errors' think 'web site has logged me out'

-------

A watchdog is usually implemented as a countdown timer that resets the processor when it reaches zero. Then the processor task list includes a task to restart the countdown timer, which in normal operation will always occur BEFORE the countdown timer reaches zero.

However, if the processor stops processing, either because it has jumped out of the program due to noise, cosmic rays, etc., OR it gets 'stuck' waiting for something to happen, such as the cloud server to respond nicely, then the countdown timer will eventually reach zero, and reset the processor.

I have sympathy with your original question of checking to see if the connection needs to be restablished, but perhaps they have not implemented that approach in favour of requiring all clients to have a reset mechanism, be that a watchdog, disgruntled wife and her husband, or whatever.

The Readme suggests the Atmel processor based boards include the required watchdog hardware, but I am guessing that the ESP boards may not. (I haven't checked --- I know many Microchip processors have a watchdog provision, but I haven't had much experience with other products.)

So it could be, your best (only practical?) approach is to try to build in a watchdog. In principle, it might be possible to rewrite the AndroidCloud.update software to time out, attempt a reconnect calling the AC.begin routine, etc., but that is unlikely to be a trivial exercise.

I only watched a few seconds of the link @byron suggested, but, in the absence of suitable hardware function in the processor, I think a 555 timer acting as an analogue timer could probably be persuaded to do an equivalent job, so I would start by watching it. It is certainly a cheap solution from component cost viewpoint, providing you don't mind a little soldering on a perfboard or similar. There may be other suggestions on the web as well.

Good luck!


   
huckOhio reacted
ReplyQuote
b
 b
(@b)
Noble Member
Joined: 4 years ago
Posts: 912
 

@huckohio @davee

As it happens I was perusing a doc on micropython on ESP32 when I saw the last email message so I looked at the docs and there is indeed a class for a watchdog timer, so the ESP32 must have one inbuilt. 

And of course you can program the watchdog in C++ if you want.

image

The micropython info is in the small image that I suppose you can blow up for reading 😎 


   
huckOhio and DaveE reacted
ReplyQuote
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

@davee

Thank you for the reply.  I am looking at the watchdog approach now.


   
ReplyQuote
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

@byron

Thanks again!  I'll start digging into the watchdog approach.  


   
ReplyQuote
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

@davee

I read the Github FAQ and it did answer one question...what's the purpose of the AC.update which is resetting the watchdog timer which may explain why the display flashes on/off with each cycle through the loop (but not enough time to 'reset' the connection to the cloud).  I can see where this would be checking to see if the PICO code is still running but I don't think this is verifying the connection to the cloud.  The "flash" is only a second or two, not enough time to reset the connection.  

The FAQ mentioned that the watchdog functionality was being added to all ATSAMD21G18 boards.  I am waiting for my new PCB so I can port the code over to the NANO 33 IOT which is SAMD21 based board.  Should have the boards next week.

Thank you for the link!


   
ReplyQuote
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

@byron @davee

Another question.  In the above mentioned FAQ was the line 

Although the watchdog is automatically enabled it can be disabled by setting the second parameter of ArduinoCloud.begin(...) to false:
ArduinoCloud.begin(ArduinoIoTPreferredConnection, false).

Where can I find these commands and the associated parameters?  I am new to github and have looked around but can find any other documentation.


   
ReplyQuote
DaveE
(@davee)
Prominent Member
Joined: 2 years ago
Posts: 787
 

Hi @huckohio,

  Sorry, I am probably newer than you to Arduino as such, but Google only came up with the 'Get started' for Arduino Cloud ... which has no details, and is apparently out of date,  plus the GitHub site and a forum mention or two. I suspect you are at the 'bleeding edge', just behind the latest developments, but of course failing to find something doesn't mean it's not there. Perhaps @byron has some ideas?

So I fear it is GitHub ploughing throuh the code .. and maybe the Anduino forums ...

Good luck with the new boards!!!


   
ReplyQuote
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

@davee

It looks like the problem is with the Arduino IoT Cloud dashboard.  I connected the Nano 33 IoT version of the circuit to the PC and it powered right up.  I opened the cloud application and when to the serial monitor and I can see the messages.  So I can see that the board is talking to the cloud.  Then I opened the dashboard and it is not receiving the correct temp and none of the buttons function.  Looks like the problem may be in the dashboards.  I'll start searching for issues.

Thanks for the assistance.


   
ReplyQuote
huckOhio
(@huckohio)
Reputable Member
Joined: 3 years ago
Posts: 249
Topic starter  

Upon further testing I observed that when the Nano 33 IOT does not connect/or loses connection with Arduino IoT cloud, the Nano 33 IoT will reset (disconnect and then reconnect).  The problem appears to be in talking with the Dashboard.  I tried the Dashboard for the Pico and Nano and neither are updating/sending data.  I created a new dashboard and it wouldn't update either.  This has been happening for a week.  Not sure if there is a problem with my system or with Arduino IoT Cloud.  More searching.....


   
ReplyQuote
b
 b
(@b)
Noble Member
Joined: 4 years ago
Posts: 912
 
Posted by: @huckohio

Where can I find these commands and the associated parameters

I saw this in the Arduino Docs for the IOT Cloud.  I dont know if it would help your case but I post a snippet that refers to obtaining debug info on the state of the network connection to the IOT Cloud  

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}

But I think whatever you do on an ESP32 it likely that at some point it may fail and need a re-boot.  An external watchdog may save a trip to the bunnies on a cold winters evening. 🤨 


   
ReplyQuote
Page 1 / 2