[RELEASE] ST_Anything v2.9.2 - Arduino/ESP8266/ESP32 to ST via ThingShield, Ethernet, or WiFi

arduino
alarm
dth_misc
esp8266
esp32

(Dan) #2247

So, it was working and now it’s not? Did you happen to delete the timed relay child devices without deleting the parent? If yes, delete the parent and recreate it manually as you did before.


#2248

Yep. Done that. No joy: After success with setting up a timed relay I deleted the child and parent from ST. (I didn’t want a pulsed output. I want switched output. So I reset and started over.) I uploaded ST-anything-multiple to ModeMCU with wifi credentials. Added new “Anything parent” device in ST ide. All good. Configured device on phone using credentials. Still all good, but this is where I expect to see a child device automatically generated for the switch defined in the Multi sketch, but it doesn’t generate. In fact no children generate from the Multi sketch. They should, right?


(Dan) #2249

Yes, it will create children if you correctly edited the sketch with more than just WiFi credentials (needs ST Hub IP address as well), and entered into the Parent Device’s settings the MAC address, is address, and port of the MCU.


#2250

Ya, I think I added all the required info, but I’ll do it all again. It’s a new day… fresh eyes. Good to know with certainty what the finished product is supposed to look like. Fantastic work. Thanks so much.


(cslee) #2251

Dan,
I’m working on a device which uses a Arduino Mega to control about 48 relays. It uses most of the IOs on it. But I still have 2 serial port pins. I want to run ST_Anything on with a ESP12 as the wifi part. How do I partition the code between the two device?
Any ideas?

thanks,
chin


(Dan) #2252

48 relays!!! What are you going to control with all of those relays? Wow! You’ve made me curious.

As for using an Arduino MEGA + ESP WiFi, I do not recommend trying it. I have never had good luck with that combination being reliable. Use an Arduino MEGA + W5100 Ethernet shield if you want good, reliable performance.

Or, use a few NodeMCU ESP8266’s or NodeMCU ESP32’s instead. The ESP32 board has quite a bit of GPIO onboard already and has built-in WiFi.

BTW - Here’s a link to my GitHub repo where I discussed using an Arduino MEGA + ESP01 combination with another user.


(cslee) #2253

Dan, Its’ a 16-station whole house intercom master station retrofit. I’m reusing the slave units. I even design a PCB for the relays as wiring by hand would be a nightmare. Thanks for the pointer I’ll look into it.


(cslee) #2254

Dan, another question. You mentioned in that other github repo that by default it uses “Serial1”. Can I change it to Serial0 as I left Serial0 unused on my PCB. If not I have to mod my board even more. So far, I didn’t have to do much modding. It was my first PCB design.


(Dan) #2255

I assume when you say “serial0” that you really mean “Serial”, correct? It is not really possible to use those pins (0/1) as they are used for USB communications. You would have to perform extensive code modifications to ST_Anything and the corresponding SmartThings… libraries to remove all Serial.print Debug statements that display data to the Arduino IDE’s Serial Monitor Window. Even without a USB connections, the code is trying to use pins 0 and 1 for this traffic.

The following is from https://www.arduino.cc/reference/en/language/functions/communication/serial/

Used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port (also known as a UART or USART): Serial. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output.
You can use the Arduino environment’s built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to  `begin()` .

Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board). Don’t connect these pins directly to an RS232 serial port; they operate at +/- 12V and can damage your Arduino board.

The  **Arduino Mega**  has three additional serial ports:  `Serial1`  on pins 19 (RX) and 18 (TX),  `Serial2`  on pins 17 (RX) and 16 (TX),  `Serial3`  on pins 15 (RX) and 14 (TX). To use these pins to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega’s USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device’s RX pin, the RX to your device’s TX pin, and the ground of your Mega to your device’s ground.

Before you try to go much further, I would recommend that you try to use an ESP01 as a WiFi dongle/shield to see if you can even make it work reliably. If you have to switch to a W5100 Ethernet shield, you will be losing the use of some other pins as well.


(cslee) #2256

Dan, Yes, I meant pins (0/1). Thanks again. I’ll hack the board to connect ESP-01 to pins 18/19 for Serial1.


(Dan) #2257

FYI - You can also use Serial2 or Serial3 if that somehow made things easier.


(cslee) #2258

It’s not going to be any easier. But if I have to how do I change it to use Serial2/3?


(Dan) #2259

In your sketch, you simply change the following “Serial1” references to either “Serial2” or “Serial3”. This was taken from the ST_Anything_Multiples_MEGAWiFiEsp.ino example sketch.

  //*****************************************************************************
  //Initialize the "Everything" Class
  //*****************************************************************************
  
  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  
  //Create the SmartThings WiFiEsp (ESP-01) Communications Object
    //STATIC IP Assignment - Recommended
    st::Everything::SmartThing = new st::SmartThingsWiFiEsp(&Serial1, str_ssid, str_password, ip, serverPort, hubIp, hubPort, st::receiveSmartString);
 
    //DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
    //st::Everything::SmartThing = new st::SmartThingsWiFiEsp(&Serial1, str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Initialize the Serial1 baudrate to match your ESP-01's baud rate (e.g. 9600, 57600, 115200)
  Serial1.begin(115200); 
  
  //Run the Everything class' init() routine which establishes Ethernet communications with the SmartThings Hub
  st::Everything::init();

(cslee) #2260

Thanks again.
BTW, here’s the board I designed.

It’s a shield for the Arduino mega.


(Dan) #2261

Very nice!


(Kampto) #2262

You can add wifi to the Mega using a esp01 board and this adapter.

Use Mega’s hardware serial pins 18, 19.
Use the follwing AT commands to set the ESP01 from the serial monitor.
AT+CWMODE=1 Set to station, 1= Sta, 2= AP, 3=both,
AT+CIOBAUD=9600 to permanently change buad rate to 9600 or other, Note change sketch code to 9600 after

I have my Mega working this way for a year now without issue.


(cslee) #2263

Thanks for the info.


(cslee) #2264

Dan,
Another question. I will have my sketch running on the Mega. It has it’s void setup and void loop. I will want to add ST_Anything to it and I want to create some ST buttons where I can use it to override something in my sketch. Say I have ,

bool OVERRIDE[3] = {FALSE, FALSE, FALSE};
int B_STATUS[3] = {0,0,0};
I want to be able to set OVERRIDE bits from ST. and I want ST to get the B_STATUS.

Can you give me some guidance? maybe some code snippet/pointer.

thanks,

Chin


(Dan) #2265

It is always best to start with one of my example ST_Anything sketches and then make changes from there.


(cslee) #2266

kampto.
Where did you get your ESP-01? I am using some I have, it seems to be having trouble. I loaded an empty sketch to Arduino and I was able to set the CWMODE and BAUDrate without a problem. STAnything seems to be able to see the ESP-01 but it cannot get past “Attempting to connect to ….”

If I user the serial monitor to ESP01, I can use the AT commands to connect to the wifirouter and I can ping it remotely. I’m thinking the firmware on my ESP-01 is old.

thanks
chin

Here’s my AT logs:

AT+RST

20:21:41.236 ->
20:21:41.236 -> OK
f⸮⸮Ybz⸮⸮@⸮r⸮B⸮⸮KZ⸮b⸮⸮
20:21:42.493 -> [Vendor:www.ai-thinker.com Version:0.9.2.4]
20:21:42.540 ->
20:21:42.540 -> ready

AT+GMR

20:21:59.738 -> 0018000902-AI03
20:21:59.785 ->
20:21:59.785 -> OK

AT+CIFSR

20:22:47.010 -> 192.168.1.19
20:22:47.010 ->
20:22:47.010 -> OK