|
Post by papa on Sept 30, 2022 19:25:31 GMT
Reserved for Latest Programming of ESP32 WiFi MQTT Nodes: I have begun adapting the node choices code to ESP32 WiFi boards from Arduinos with RFM69 or RFM95 antennas. I & others expanded computourist's original DHT End Node sketch to produce the node choices sketch. In this easy to find post, I will begin providing the latest sketch version. Below I'll first provide some introduction, preparation, & document getting started.
At the end of the downloadable sketch will be a version history, summary of possible nodes, & some documentation. This post will usually have the latest ESP32 node choices sketch in the next line.
ESP32_nodes_n006Hpub.ino (44.44 KB) << From here, Forum members (free registration) can download the ESP32 Nodes sketch. ^^ Updated & corrected Oct. 28, 2022 to fix DHT glitch.
^^ This version includes BUTTON, BUTTONIO, ACTOR, SWITCH1, SWITCH2, SWITCH3, OLED display, PIR Motion Sensor (incl Interrupt) & DHT (temp/humidity sensor).
Important: To use this programming, you need something like Arduino IDE & its ESP32 addon. See this post below. Before uploading this sketch, customization is usually needed. See below ...
Next, Latest Initial Customizing for ALL ESP32 Nodes
|
|
|
Post by papa on Sept 30, 2022 19:35:11 GMT
Reserved for Latest Initial Customizing of ALL ESP32 Nodes
In the Arduino IDE, open the sketch that will be in the just above post & customize it. As an early sketch line says, "Customize your node starting at line XXX." Go to line XXX & see near there the line number where the customizing section will end. Initial CustomizationnodeID must be a unique number for each WiFi device, but should be a unique node number in your openHAB system. When I document each node, I will suggest a number (starting with 35).
wifi_ssid_A, wifi_password_A edit in your SSID & password
If you have another WiFi station, edit in that info to wifi_ssid_B, wifi_password_B. Otherwise, give B the same WiFi info as A.
For mqtt_server, edit in the IP address of your computer that hosts the mqtt broker.
For SERIAL_BAUD, match the rate you set in the Arduino IDE Serial Monitor
=========================================
Before uploading programming to the node, also do the node's added customization found where the node is documented more specifically. Often just return to the thread & post that sent you to this thread for the Latest Initial ESP32 Node Choices Sketch & Customization. Again, you may go to this post & see hints of the types of nodes one might program with the sketch that will be provided in this thread. Next, Introduction
Then, Hardware Possibilities for ESP32 Nodes
|
|
|
Post by papa on Sept 30, 2022 19:43:08 GMT
MQTT Nodes on ESP32 Dev Boards, Introduction
My DIY home automation still uses several 3.3 volt Arduino compatibles. However ... Reliable 3.3 volt Arduinos are becoming less available. Prices for them plus RFMxx antennas are not necessarily much better than ESP32 boards with included WiFI. Beside the Arduinos are older technology & have less memory for programming. For Arduino nodes' communication, we have to install an RFMxx antenna & make an RFMxx Gateway.
ESP32 development boards (like the Sparkfun ESP32 Thing) work nicely to communicate via WiFi. They also offer several pins for connecting sensors, etc. Some like the Thing have connections & charging circuits for LiPo batteries.
This forum's code for several RFMxx nodes could be adapted to ESP32 dev boards & could connect more directly to openHAB, etc. via MQTT & WiFi. (No Gateway necessary)
This thread will begin offering code & documentation for ESP32-WiFi-openHAB Nodes. Who would be willing to help develop this new offering?
(The camera code is extensive & complicated so I left it out of this thread's offering.)
Next: Hardware Possibilities for ESP32 Nodes
|
|
|
Post by papa on Sept 30, 2022 20:38:24 GMT
Hardware Possibilities for ESP32 Nodes My criteria for ESP32 Boards: - Many ESP32 pins are exposed to board edge connections - Board edge connections with female headers or unpopulated so I can add female headers. (I use female headers to connect LEDs, sensors, etc.) - Pinouts & other helpful documentation are available
- Possible added features like usable board button or LED or OLED screen. - USB connector for Arduino IDE programming & Serial Monitor debugging output. - Ideally 3 or 4 GND pins (enough for sensors, LEDs, etc)
ESP32 Boards Used or Considered So Far:
The Sparkfun ESP32 Thing (see here or here) is a good product with much documentation. That board includes a usable button & blue LED. One can separately order female headers of the right length. Besides 4 GND pins, it has connections & charging circuits for LiPo batteries. The HiLetgo 0.96" ESP32 OLED Board (See here) has less docs & available pins, but has an OLED screen & is OK & costs less than the ESP32 Thing. Apparently, it's similar to a Wemos Lolin32 board, but does not have LiPo battery circuit. It has 3 GND pins.
So far I've begun to successfully use both of the above boards & will document more later. Other possibilities I do not have yet: HiLetgo ESP32 S2 Mini WiFi Board (See here). This board is even cheaper, but it has less power pin connections & uses a USB Type C connection. Wemos Lolin32 board (See here & here). Like the HiLetgo 0.96" ESP32 OLED Board, but has Lithium battery interface, 500mA Max charging current Next, Parts That Could Be Useful,
|
|
|
Post by papa on Sept 30, 2022 20:44:35 GMT
Parts That Could Be Useful
(Besides soldering equipment & supplies)
Female Headers (0.100 inches or 2.54 mm between sockets) ESP32 Thing has 20 pins on each side. HiLetgo OLED ESP32 has 10 pins on one side & 16 pins on the other side.
On each of two sides HiLetgo ESP32 S2 Mini has 8 rows of double pins
Dupont cables (color-coded to better show connections ?): Male to Male & Male to Female
Colored LEDs (yellow, green, blue ?)
100 ohm resistors to add to the LEDs
Various sensors
I will look at buying or making shields to stack on top of an ESP32 board's female headers. (This could help multiply power & other connections when the board does not have enough.)
Perhaps this much in this thread will help you get prepared to use the ESP32 Node code offered in the first post above.
|
|
|
Post by papa on Oct 2, 2022 21:20:05 GMT
ESP32 Pins to Use or Not Updated Oct. 4, 2022
ESP32 Pins on these boards seem standard. However not all pins are exposed to board edge connectors & some pins exposed on the edge have reserved functions. Some boards may expose more or less pins than other boards. Usable pins (if exposed & not otherwise claimed): 12, 13-19, 21-23, 25-27, 32, 33. Input only: 34-36. 39
Pins that might be usable with caution: 0 (zero) might be pulled down & connected to board button or switch. 2 or 5 (Sparkfun ESP32 Thing) may be hardwired to board LED. 4 & 5 may be hardwired to I2C OLED screen (e.g. HiLetgo ESP32 OLED Board) When using 12 for input, don't pull it high or board's boot will fail.
Recommended to avoid: 1, 3, 6-11
Update, April 23, 2023, on the HiLetgo OLED ESP32, I'm sometimes not able to use these pins: SVP, SVN, 25, & 26.
Next, Some Sample Pinouts of ESP32 Boards
|
|
|
Post by papa on Oct 2, 2022 21:33:29 GMT
Some Sample Pinouts of ESP32 Boards << Forum members, click on pics for larger view HiLetgo OLED ESP32
HiLetgo ESP32 S2 Mini
|
|
|
Post by papa on Oct 3, 2022 21:32:44 GMT
Another Requirement to Meet: MQTT Broker (Mosquitto)
These ESP32 nodes are intended to communicate via MQTT to openHAB or other MQTT capable application. In fact, these nodes will not work until they connect with WiFi & a MQTT broker. So on your appropriate computer, install the MQTT broker named Mosquitto. Last I knew RaspberryPi had an option for this in the openHABian install. Next, More Requirements to Meet: Arduino IDE & Getting the ESP32 Add-On
|
|
|
Post by papa on Oct 3, 2022 21:35:14 GMT
More Requirements to Meet:
Arduino IDE & Getting the ESP32 Add-On
This site was helpful. It instructed installing the needed Arduino IDE & the ESP32 Add-on for Windows & Mac/Linux. In preparation for programming an ESP32 board, install the needed ESP32 add-on. In Arduino IDE, go to File\Preferences In the “Additional Board Manager URLs” near the bottom of Preferences, enter the following & click the OK button. If other URLs are in the box, end the list with a comma & then add this URL:
https://dl.espressif.com/dl/package_esp32_index.json
Go to Tools\Board\Boards Manager. In the box near Boards Manager's top, search for ESP32 & press the install button for “ESP32 by Espressif Systems“ When the install finishes, you may close the Boards Manager. Next, Arduino IDE: Select an ESP32 Board & a Serial Port
|
|
|
Post by papa on Oct 3, 2022 21:37:49 GMT
Arduino IDE: Select an ESP32 Board & a Serial Port
The following assumes first having completed what's in the post just above. Select an ESP32 board in Arduino IDE ...
Go to Arduino IDE's Tools/Boards menu & scroll down to see & select an ESP32 board ... Your board (like Sparkfun ESP32 Thing) may be specifically listed. Apparently for HiLetgo OLED ESP32, we can select Wemos Lolin32. Selecting a specific ESP32 board may offer board-related sample sketches when you click on Arduino IDE's File/Examples menu & scroll down ...
When in doubt, as I have done sometimes, just select ESP32 Dev Module which seems generic. ====================================================== So the Arduino IDE & the ESP32 board can communicate ... Have the IDE-hosting computer & the ESP32 board connected via a working USB data cable AND ... In the IDE Tools/Port menu, make sure a serial port is selected.
Next, Barebones ESP32 Node on Sparkfun ESP32 Thing
|
|
|
Post by papa on Oct 3, 2022 21:39:38 GMT
Barebones ESP32 Node on Sparkfun ESP32 Thing Now for a simple, working ESP32 Node using the Sparkfun ESP32 Thing.
As in this post above, in the Arduino IDE, have selected an ESP32 board & a serial port. =================================== Two final customizations for this node:
1) In the sketch that you downloaded & had Arduino IDE open, find #define nodeId 35 // node ID, must be unique number for each WiFi device
If you use this forum's WiFI MQTT code, only one of your ESPxxxx boards can be 35. Use a unique number in this code line.
2) Next in the sketch, find #define MQCON As necessary, edit the line to read #define MQCON 5 That is, if necessary, delete "//" that may start the line & have the number 5 end the line. Note: Sparkfun has a small blue LED connected to pin 5. The sketch will blink the LED once to indicate WiFi has connected & then light the LED steady to indicate MQTT communication has also connected. Especially when the board is disconnected from the IDE computer, knowing that WiFi/MQTT communication is working is helpful. After you do the above, you may upload the ESP32 Nodes sketch to the Sparkfun board.
Next, Barebones ESP32 Node on Sparkfun ESP32 Thing, Expected Results
|
|
|
Post by papa on Oct 3, 2022 21:41:07 GMT
Barebones ESP32 Node on Sparkfun ESP32 Thing, Expected Results When the upload finishes, open the Arduino IDE Serial Monitor (SM). Again, The sketch should blink the small blue LED once to indicate WiFi has connected & then light the LED steady to indicate MQTT communication has also connected.
At the SM's lower right, make sure the SM's baud matches that in the sketch line #define SERIAL_BAUD 115200. It may help to press the ESP32 board's reset button. Then the SM will display boot info from the board. Then the SM should show typical Node output (my notes in [ ] : Node 35 Version ESP32_nodes_nxxx MQCON 5 [Node ID #, code version, MQTT indicator is on pin 5] Connecting to XXX [connecting to WiFi station named in sketch] .... [several dots may show while WiFi is connecting] WiFi connected IP address: 192.168.10.113 [Your IP will differ.] Connect to MQTT broker...Failed, try again in 5 seconds [Attempts to correct MQTT disconnect] Attempting to reconnect MQTT
topic home/esp_gw/nb/node35/dev99 value:NODE 35 WAKEUP: ESP_35 [wakeup reported via MQTT broker]
topic home/esp_gw/nb/node35/dev02 value:-29 [Radio Signal strength device 2, closer to zero the better] topic home/esp_gw/nb/node35/dev10 value:192.168.10.113 [IP device 10] [^^ these 2 lines of MQTT topics repeat until board disconnected ^^]
openHAB & other MQTT-capable applications can communicate with the ESP32 MQTT nodes.
Next, Barebones ESP32 Node on HiLetgo OLED ESP32
|
|
|
Post by papa on Oct 4, 2022 16:29:57 GMT
Barebones ESP32 Node on HiLetgo OLED ESP32 Preparation of LED to Indicate WiFi/MQTT Connection:
This board does not have a built in LED, but we can add one as follows. (I suggest you create two LED sof different colors while you're at it.) The goal is to create an LED with two legs about one inch long. One leg (negative) is just wire. The positive leg is wire & resistor. The following assumes you'll plug the adapted LED legs into female pin sockets.
Take an LED. Note the shorter (negative) wire lead will go to a GND pin on the board. Somehow mark that negative side. The other longer LED lead is positive. Trim that lead to 1/2 inch long.
Take a 100 ohm resistor. Trim both resistor leads to 1/2 inch long. Fold one resistor lead in half & gently crimp the folded end. (Fits snugger in a female pin socket.)
Put the other resistor lead alongside the positive wire & touching the LED's bottom. Solder side by side the resistor & positive LED lead. Trim the negative lead to the same length as the resistor plus positive lead (about one inch).
If desired, you could cover the LED leads with shrink wrap, but leave 1/4 inch bare on both ends. Carefully insert (avoid bending) the resistor lead (positive) into the board's pin 12 socket. Insert the wire only lead (negative) into the GND pin on 12's side of the board. (You could use another usable IO pin & GND pin. I'll use 12 for MQCON in the following.)
Next, Barebones ESP32 Node on HiLetgo OLED ESP32 Board
|
|
|
Post by papa on Oct 4, 2022 18:43:54 GMT
Barebones ESP32 Node on HiLetgo OLED ESP32 BoardFollow the instructions in this post above, BUT make these changes for this board: For Tools/Board, select Wemos Lolin32 or perhaps ESP32 Dev Module In the ESP32_Nodes sketch, edit the one line to say #define MQCON 12 (with no "//" at the line's start) You could adapt the above to other ESP32 boards. A different IP address. MQCON 12. If you changed nodeId in the sketch, a different Node number will be seen throughout IDE Serial Monitor output.
Next, Links to ESP32 Nodes with a Specific Sensor or Output
|
|
|
Post by papa on Oct 24, 2022 19:48:21 GMT
Links for ESP32 Nodes with a Specific Sensor or Output Go to this thread for examples of basic nodes with one sensor & one output & related openHAB configuration.
See this thread on an ESP32 Node (SWITCH) for Door, Gate, Window, Mailbox...
|
|