Recommend on how often a device should send a message without overloading "Parse"

@chuck.schwer

Hi,
I am building a WiFi sensor for use with my Hubitat. I am using smartthings library (courtesy of ogiewon) to communicate with Hubitat.

Questions is: What is a good rule of thumb on how often I can call the smartthings:run() command, which generates an event(s) to be parsed?

If I run it "full speed" it clearly overloads the Hubitat, or it seems so as the logs fly by. If I go too slow when I send a command to the sensor I get a read time out.

Thanks
John

You can run the "smartthings::run()" command every iteration through the loop(). All it does is check the network to see if any data has come in from the Hub, and then calls your 'callback()' routine. It also keeps the WiFi connection active on boards like the ESP8266 and ESP32. If an issue is detected, there is logic in the libraries to attempt automatic re-connection.

It is the "smartthings::send()" command that you need to make sure you do not execute every iteration through loop(). Use a millis() based timer to only send data periodically when polling an analog value. If checking a digital signal, only send data when the status changes. I would personally not send data faster than once every 15 seconds for polled data. More typical is 60 to 120 seconds. Although it really depends on the device you're reading.

Is there a reason you don't just use the full HubDuino solution? It is design issues like these that are automatically taken care of for you by the ST_Anything library. :wink: I can appreciate the desire to 'roll your own' as well. It is just that you do have to take into consideration a lot of details. :thinking:

Dan, Again thanks for the help.

Why do I do things the hard way? I simply enjoy the hunt more than the completed project. I've been in new product design my whole career, I've found that upon finishing a project (i.e. into production) I loose interest.

Regarding my Parse question...... operator error, my "if (millis() - " statement had a typo :slightly_frowning_face: The "smartthing.send("data:" + data);" was running every loop.

This Brings up a question:

I have been using

"smartthing.send("data:" + data);"

You wrote:
"smartthings::send()"

Am using the wrong syntax?


Also a Question regarding the Network info in the ino sketch.

//******************************************************************************************
//ESP8266 WiFi Information    CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
String str_ssid     = "yourSSIDhere";                            //  <---You must edit this line!
String str_password = "yourWiFiPasswordhere";                          //  <---You must edit this line!
IPAddress ip(192, 168, 1, 221);       // Device IP Address      //  <---You must edit this line!
IPAddress gateway(192, 168, 1, 1);    //router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!

What is the function of the device IP address?

is it:

  1. Here is the IP I want, please assign it to me.

  2. I hope you made and IP reservation in your router as I am assuming I will be assigned this IP

Thanks
John

No, I was just typing from memory. Your syntax looks correct.

The IP address is the one that will be used upon connection to the network. By default, the MCU does not utilize DHCP. I do have an option that you could use to use DHCP (which would require a DHCP Reservation in your router to prevent it from changing.)

I'm not sure I understand. It sounds like you are describing my #2.

I wouldn't worry about DHCP as long as I know what is going on.

Currently I have an IP reservation for the IP listed in the sketch. Works fine except the router does not recognize the device name nor IP. Both are listed as unknown although the MAC address is shown.

But I'm fine the way it is, just trying to understand its meaning.

Thanks
John

In the SmartThings ESP8266 library, you’ll find multiple C++ constructors. The first one shown below requires you to specify all of the network parameters. It is analogous to setting setting your PC up with a statically assigned IP address, subnet mask, gateway, DNS address...

The second C++ constructor uses DHCP.

All of my examples default to using the first constructor.

	//*******************************************************************************
		/// @brief  SmartThings ESP8266 WiFi Constructor - Static IP
		///   @param[in] ssid - Wifi Network SSID
		///   @param[in] password - Wifi Network Password
		///   @param[in] localIP - TCP/IP Address of the Arduino
		///   @param[in] localGateway - TCP/IP Gateway Address of local LAN (your Router's LAN Address)
		///   @param[in] localSubnetMask - Subnet Mask of the Arduino
		///   @param[in] localDNSServer - DNS Server
		///   @param[in] serverPort - TCP/IP Port of the Arduino
		///   @param[in] hubIP - TCP/IP Address of the ST Hub
		///   @param[in] hubPort - TCP/IP Port of the ST Hub
		///   @param[in] callout - Set the Callout Function that is called on Msg Reception
		///   @param[in] shieldType (optional) - Set the Reported SheildType to the Server
		///   @param[in] enableDebug (optional) - Enable internal Library debug
		//*******************************************************************************
		SmartThingsESP8266WiFi(String ssid, String password, IPAddress localIP, IPAddress localGateway, IPAddress localSubnetMask, IPAddress localDNSServer, uint16_t serverPort, IPAddress hubIP, uint16_t hubPort, SmartThingsCallout_t *callout, String shieldType = "ESP8266Wifi", bool enableDebug = false, int transmitInterval = 500);

		//*******************************************************************************
		/// @brief  SmartThings ESP8266 WiFi Constructor - DHCP
		///   @param[in] ssid - Wifi Network SSID
		///   @param[in] password - Wifi Network Password
		///   @param[in] serverPort - TCP/IP Port of the Arduino
		///   @param[in] hubIP - TCP/IP Address of the ST Hub
		///   @param[in] hubPort - TCP/IP Port of the ST Hub
		///   @param[in] callout - Set the Callout Function that is called on Msg Reception
		///   @param[in] shieldType (optional) - Set the Reported SheildType to the Server
		///   @param[in] enableDebug (optional) - Enable internal Library debug
		//*******************************************************************************
		SmartThingsESP8266WiFi(String ssid, String password, uint16_t serverPort, IPAddress hubIP, uint16_t hubPort, SmartThingsCallout_t *callout, String shieldType = "ESP8266Wifi", bool enableDebug = false, int transmitInterval = 500);

One more thing... the ShieldType parameter is actually used to create the Node Name of the micro-controller.

Oh, and one more thing... the TransmitInterval parameter is the maximum rate that data will be sent to the hub, in milliseconds.

1 Like