Hello... I am just getting started with Raspberry PI and ESP32. I came across your channel and am thoroughly impressed. Your content is awesome... 100% on point as it's precise, accurate and easily understood. Well done sir... 10 out of 10!
Thanks for the tutorial, loved your pace of delivery and lack of waffle. It would be great to see several sensors collecting data, with time-date stamps when the sensor readings were captured, sending these to a data log on the Pi.
Thanks for this tutorial. As a beginner, it covered the basics which really helped me get my ESP8266 up and running as a MQTT client. I really appreciate your hard work putting this together. thanks!
Your video clips are great. Very helpful are the links to the written tutorials. These help a lot when one is a beginner to this matter and when one does not speak English fluently (you speak a bit fast). Please carry on with uploading such interesting tutorials, thanks.
Amazing Explanation...Is it neceassary to make use of breadboard for the connections? can we directly connect DHT22 with ESP32 using F-F jumper cables?
great video, very well explained. About the wifi issue on esp32 board, I had exactly same issue when importing the network module. Have you done any further troubleshooting or found a way to correct it ? For now I'm proceeding with a different board as well, but I was wondering if defected one could be fixed. Thanks!
It's a gamble buying generic ESP32 boards on eBay. They often have bad soldering and use rejected parts. I think the only problem is the defective micro-USB port. The board would probably be fine if I replaced it. One work-around is to connect the Pi's 5V pin directly to the ESP32's 5V pin and connect the grounds. This should protect against brown outs caused by a shoddy USB port or cable. Since switching to the Wemos Lolin32, I have not encountered any problems.
Nice tutorial, thanks. I don't run Unix so adapted what you were doing to the Thonny IDE which I have just loaded (looks quite good). My second sketch (?) after doing a blink one. Had to modify one line to include port (not sure it was necessary), user and password for the Mosquito broker running on a Pi under Home Assistant... client = MQTTClient(CLIENT_ID, SERVER, port=1883, user=b"username", password=b"password") I tried adding them in the simple.py program but that didn't work! Still lots to learn, I can see it's working by using MQTT Explorer on my PC.
I like your video's. They are very helpful and understandable. I want though, the same video's with NodeMcu esp8266 if possible. Please cover topic with 2 ore more switches and relays as well. Thanking in advance.
Wonderful video for a beginner like me. I've got a question. How would you add a display to the sensor board so that you could monitor the temp/hum at the site? That would be extremely handy.
The same OLED display could be used on the ESP32. I have a video on color OLED displays: th-cam.com/video/a7DrFqqu-78/w-d-xo.html You should also look at the LoBo build because it comes with a very robust display library: github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki LoBo has recently added support for FTDI EVE displays which are very powerful.
@@rdagger Thanks so much for the reply ! I'm kind of new to this. Took Fortran about a million years ago and never programmed again until I bought a Pi and am trying to learn Python and Debian. I just found your channel and I love how detailed you are and how fast you pull a project together. Your website is next. I have dozens of ideas to investigate from automating a whole house wood stove to signal and brake lights on an RC truck. Also kodi and a cloud server, security cameras and hydroponics. I am somewhat overwhelmed with all the information available and how fast it is changing but that is half the fun. Between the piles of books, online courses, TH-cam and adafruit I don't know where to start. Linux is new to me and I am well past my optimum learning years so I have my work cut out. Again, thanks for the reply. You will be hearing more from me.
Great video, thank you. You can press Ctrl+L to clear terminal instead of typing clear. What is the approximate system load on the Raspberry Pi ? Could you possibly run htop while the MQTT is running?
I use the clear commands as markers when I'm editing the video. Also my pace is very fast so I try to avoid keyboard shortcuts, command history and tab completion to make it easier to follow. Mosquitto is very lightweight. I don’t have anything currently set up to test the resources properly. Just starting the broker has the follow results; PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command 1202 mosquitto 20 0 8776 4744 4260 S 0.0 0.2 0:00.28 /usr/sbin/mosqu
@@rdagger Thanks for quick reply, You can use htop to monitor system resources in runs from a terminal. Install with sudo apt install htop To run, open a new terminal and type 'htop' to monitor your system. The difference is you get a CPU useage graph for each core and use of colour easier to read than top.
Thanks! I have not experimented with packet injection. There was a relevant thread on the MicroPython forum: forum.micropython.org/viewtopic.php?f=16&t=3389
I think that if you put a 4 sec wait before first reading, it might work better when starting in the beginning? You should propably post temperature and humidity on different subjects. And voltage level are also good to have posted through MQTT so users knows when to change batteries. mDNS would also be a good way to connect the MQTT server without knowing its IP address. And yes, great tutorial, thanks.
rdagger68 many home routers also uses DHCP to set the name used by the device to register as solvable name through its DNS. Would be greate if more computers uses mDNS.
Hello excellent video, I am building something similar to your example, I use the Lolin32 and a max31865 for a temperature sensor. I have a question: what kind of library or code do I need to connect the MAX31865 to the esp32? I'm a total beginner so if you could give me step vy step advice I would appreciate, Thank you.
I haven’t used the MAX31865 but there is a MicroPython ESP32 library for it on GitHub: github.com/htlb-atk/schilf-iot-MAX31865 The library has excellent documentation (German): htlb-atk.github.io/schilf-iot-MAX31865/
The SSD1306 display is connected to the Raspberry Pi, which is running Python 3 code (not MicroPython). The Adafruit SSD1306 driver is a Python 3 library designed for the Raspberry Pi and Beaglebone Black. One of the great features of MQTT is that it allows communication between systems running different programming languages.
Hey i have another doubt At 7:12 we have the data being converted to the byte format My question may sound silly but i would like to know if that works for all sensors or just for DHT specifically (i e,can i convert the data from any sensor to the byte format using this syntax or is there any other specific syntax)
It's not DHT specific but I think that the latest version of Python no longer supports using the format method with the bytes type. However, if you wanted to achieve the same bytes conversion, you could use the following if formatting is necessary: msg = f'{t:3.1f},{h:3.1f}'.encode('utf-8')
Hi to all, this tutorial was great and very helpful, thank you very much. A quick question from you expert guys, Can I connect a Temperature Sensor which uses resistance (milliOhm) as its output? or in another word does the ESP32 or other series of ESP... take resistance input in any of its pins (GPIOs, etc.)? more clarification is: currently my resistance temperature sensors are connected to a I/O card that follows Resistance Temperature Detector (RTD) and receives the changes in the resistance of the temperature sensor and I wanted to make the temp. sensors wireless with utilizing ESP... .
Yes you can measure resistance using the analog pins on the ESP32. You can do this by creating a voltage divider comprised of 2 resistors. The first resistor is your variable resistance source (a sensor that varies resistance). The second resistor is a fixed value (close to the range of your sensor). As the sensor changes resistance the voltage output of the divider will vary and the ESP32 analog pin can measure it. UNFORTUNATELY, most RTD sensors require a very high quality amplifier such as a MAX31865 RTD-to-Digital converter. I think Adafruit sells a MAX31865 breakout board that can be connected to the ESP32 using SPI protocol. In my 4th video of this series, I show how to connect and measure a SoftPot using the analog pins on the ESP32. A SoftPot is a potentiometer which is a voltage divider. th-cam.com/video/a7DrFqqu-78/w-d-xo.html
Hi again rdagger68, I have discussed what you said with our electrical technician, but he was rather confused, can you provide drawing or diagram of this circuit (if it is not too much to ask) ? (email: babaknasiri36@gmail.com)
Generally speaking, an RTD sensor requires a very high quality amplifier such as the MAX31865: www.adafruit.com/product/3328 Therefore, a simple voltage divider approach would not be sufficient. A voltage divider could be used with thermistor as in this Arduino example: learn.adafruit.com/thermistor/using-a-thermistor
Is it possible to use an ESP32 to do a PWM from analog inputs to a PPM output string? A radio control receiver needs to read the PPM transmitted over the air which it then parses out the individual channels (PWM from the analog inputs) from the PPM string (frame) to send to the corresponding servo. There's a delay at the end that signals the end of the PPM frame which tells the receiver to get ready for the next frame. What I would like to do is take each analog input and convert it into an 11bit value between .9 and 2.1ms and make a PWM signal. There would be 6 channels and each PPM frame would be 20ms total. So the max would be 2.1x6=12.6ms for all channels(PWM values) + (20-12.6, the delay period) = 20ms total. The PPM frame is output from the ESP to an RF deck which would transmit it to the receiver. It would need to output the PPM signal at at least 50hz preferably 60. I know this can be done with an Arduino but these seem smaller and it would be cool to have an option.
Reading the ADC inputs should be no problem using the ADC class. The PPM is more difficult. There are existing libraries for decoding ppm: github.com/dastultz/micropython-ppm-decoder & github.com/jeffeb3/cppm_micropython I haven’t seen any MicroPython encoding libraries. I haven’t worked with ppm. I assume you need to generate waveforms. The ESP32 hardware should be able to accomplish this but I don’t know if MicroPython affords the necessary control. You can create analog waves using the DAC class: micropython-docs-esp32.readthedocs.io/en/esp32_doc/library/pyb.DAC.html and the LoBo build has a DAC module that might work: github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/dac I suggest you post your question to the MicroPython forum: forum.micropython.org/
The program should continue to run after you exit rshell. You can always press the reset button to restart your program. I'd run your program from main.py instead of boot.py.
Hi, your tutorials are really excellent, thanks for doing that. We're using ESP32 as "motes" sending MQTT data to Node-RED on a Pi, so your instructions are right on. But did you know your website seems to be down? Best Regards, A
You can also just do Downloads/esp then press tab and it should auto complete the file name if you want to avoid the annoying process of copy paste in terminal.
Hello. It is necessary to put a delay in client code to transmit the data? What will happen if i didnt put some delay? What is the minimum delay if it is required?
Your tutorials are fantastic.Thank you for them.I am stuck on the "import network" part. Nothing happens when I run this command in repl. Do you know where the problem might be ?
After I type import network ,nothing happens. When I hit enter I just get >>> .So REPL is not frozen ,I am just not getting any information on screen.When you type " import network" in the video ,a lot of information is printed on screen starting with wifi firmware version.
Your build might have the debugging messages turned off. Does your boot.py file contain the line esp.osdebug(None), this would turn off the messages? You can try manually turning on the debugging messages by typing the following before the import network statement: import esp esp.osdebug(0) Also if you plugged anything into UART0, you should remove it first.
I am getting this . Do you have any ideas what could be wrong ? I have 2 boards and the same problem with both. >>> >>> >>> import network >>> station = network.WLAN(network.STA_IF) I (108515) wifi: wifi firmware version: 111e74d I (108515) wifi: config NVS flash: enabled I (108515) wifi: config nano formating: disabled I (108515) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (108525) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (108545) wifi: Init dynamic tx buffer num: 32 I (108545) wifi: Init data frame dynamic rx buffer num: 64 I (108545) wifi: Init management frame dynamic rx buffer num: 64 I (108555) wifi: wifi driver task: 3ffe1620, prio:23, stack:4096 I (108555) wifi: Init static rx buffer num: 10 I (108565) wifi: Init dynamic rx buffer num: 0 I (108565) wifi: Init rx ampdu len mblock:7 I (108575) wifi: Init lldesc rx ampdu entry mblock:4 I (108575) wifi: wifi power manager task: 0x3ffe854c prio: 21 stack: 2560 W (108585) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration Brownout detector was triggered Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled. ets Jun 8 2016 00:22:57 rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0018,len:4 load:0x3fff001c,len:4332 load:0x40078000,len:0 load:0x40078000,len:10992 entry 0x4007a6c4 W (66) rtc_clk: Potentially bogus XTAL frequency: 35 MHz, guessing 40 MHz I (357) cpu_start: Pro cpu up. I (357) cpu_start: Single core mode I (357) heap_init: Initializing. RAM available for dynamic allocation: I (361) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (367) heap_init: At 3FFDCE10 len 000031F0 (12 KiB): DRAM I (373) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM I (379) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (386) heap_init: At 40090060 len 0000FFA0 (63 KiB): IRAM I (392) cpu_start: Pro cpu start user code I (186) cpu_start: Starting scheduler on PRO CPU. OSError: [Errno 2] ENOENT MicroPython v1.9.3-332-g27fa9881 on 2018-02-19; ESP32 module with ESP32 Type "help()" for more information. >>>
Since the Brownout detector was triggered, I think you have a power issue. The Wi-Fi module draw a lot of power when activated. The are several possibilities: 1. Power supply is too weak, 2. USB cable too long or thin, 3. USB jack on the ESP32 is defective, 4. You have additional components connected to the GPIO pins that are drawing too much current.
A basic question. Since the ESP32 has wifi, is it possible to set it up so that it connects to wifi automatically on power up and then runs the micropython code to publish the data. It seems to me that if the only way is to keep it connected to the Raspberry Pi, then that defeats the purpose, somewhat. Ideally, one could have the rshell running remotely over wifi to connect. I don't have an ESP32 but was thinking of getting one. ETA: just saw your next video which has the main.py Still remaining: can rshell connect remotely?
In the 6th video of this series I demonstrate the LoBo build of MicroPython which comes with built-in FTP, Telnet and mDNS. This affords wireless REPL access and file management. With respect to Rshell, it might be possible to set up wireless serial communication but I don't know. You could ask Dave the creator of Rshell: github.com/dhylands/rshell
Thank you. This looks to be a great series. I have only finished the first two. ETA: It also appears that webrepl for ESP32 is also available in the following fork: github.com/Hermann-SW/webrepl From: forum.micropython.org/viewtopic.php?f=2&t=3124&p=30434&hilit=esp32#p30434
There are MQTT apps for iPhone and Android. I also have MicroPython videos that demonstrate a web server and web sockets for the ESP32. th-cam.com/video/xscBwC1SrF4/w-d-xo.html th-cam.com/video/uzY6aSg9Ly8/w-d-xo.html
Their networks have to be able to speak to each other. For different networks you would need to be able to bridge them. For example, you could set up a VPN between the networks. If you are looking for a remote solution, you should check out ThingSpeak.com. The LoBo build of MicroPython has a built-in MQTT library with support for ThinkSpeak: github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/mqtt#example-connecting-to-thingspeak
Thanks for the video. Same thing I want to do using the ESP8266 (Esp-12E). i have followed the steps of this video. after reaching : "rshell --buffer-size -p /dev/ttyUSB0". it shows connect to REPL. and then give some errors. Please guide me in this regard. Thanks
Great tutorial, easy to follow and copy command lines from your website. I have got some error message when running: import dht_publish Here is what I got returned: Traceback (most recent call last): File "", line 1, in File "dht_publish.py", line 11, in File "umqtt/simple.py", line 99, in connect MQTTException: 5 Not sure how to proceed further. Line 11 in dht_publish is attempting to connect to mqtt server. I have adjusted IP address to match my RPI address. I haven't done any changes to simple.py file. My Mosquitto server is running, I am able to send message and receive it using Node Red, as well as command line in Putty, so I am not sure what else can I check and change.
I just re-tested the dht_publish code and it's working OK. Are you sure your ESP32 is connected to your Wi-Fi network? btw: youtube flags any comment with .py as SPAM because it thinks it is a hyperlink to Paraguay.
quick question: as your mqtt pub micropython code requires the server number (the IP address of the broker; in this case RasPI), isn't it essential that the raspberry pi is set up with a static IP address? (if the Pi reboots then the IP address may be dynamically changed by the wifi router)
I more reliable method would be to use mDNS. I recommend you check out the Loboris build because it comes loaded with MQTT and mDNS. My next video will probably cover mDNS. github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki
Hey great video!!!Everything went on just perfect until I came to the command Mosquitto_sub -d -t "TOPIC_NAME". upon executing this command I get this output Client (null) receiving connect Client(null) receiving Connack (0) Client (null) sending SUBSCRIBE (Mid: 1,Topic:"TOPIC_NAME",QoS: 0,Options:0x00) Subscribed (mid: 1): 0 Client(null) sending PINGREQ Client(null) received PINGRESP and the last 2 statements keep getting printed until I force quit using ^C. I have searched far and wide for a possible explanation but none of the solutions seem to work out. Could you please help?
and moreover import "FILENAME" gives me this File "dht_publish.py", line 10, in File "umqtt/simple.py", line 68, in connect OSError: [Errno 104] ECONNRESET Could you please help?
Mosquitto v.2.0 restricts access to the localhost only be default. Modifications are required to the mosquitto.conf file which is located in the /etc/mosquitto directory. Append the 2 following lines to the .conf file to allow remote computers to access the Mosquitto broker without authentication: listener 1883 0.0.0.0 allow_anonymous true
@@rdagger thank you so much!! Along with this i also found that my mobile hotspot took over the ipv6 address instead of ipv4. Adding these two lines and changing my wifi did the trick..Thanks again!
Hi, thanks for the tutorial help me a lot. I havê a tricky problem when the internet restart i loose the connection to esp32 there is any solution for this? Can someone help me?
rdagger68 , Hi yes when i restart the router i enter on raspberry and whe. I put mosquito he doesnt show anyhting on output...i need to restart DHT to see again temperature. The connection is via WiFi raspberry to DHT.
On the ESP32 you can check your Wi-Fi connection with the network library: from network import STA_IF, WLAN station = WLAN(STA_IF) Then you can wrap the publish statement to ensure it is connected: if station.isconnected(): client.publish(TOPIC, msg) else: print('Lost Wi-Fi connection.')
It is very similar to the publishing code. There are subscribe examples on the MicroPython Lib repo: github.com/micropython/micropython-lib/tree/master/umqtt.simple
Thank you for the quick response, one more question, I checked one of the example from the website, so all I have to do is change the local host to raspberry pi IP address and the topic to the topic that I want to subscribe for example the dht_publish topic ?
Is this project still supported? I've been successful with everything except to the very last bit of running dht_subscribe. Still providing help? This is my first exposure to mqtt. If I'm successful I'd like to esp32 the heck out of many things :)
I tested the code from the video last week on an ESP8266 and it worked. You may have received a bad DHT22 especially if you purchased from eBay or Ali Express. It could also be a wiring issue. Make sure you keep the wires as short as possible. There are many more reliable temperature / humidity sensors available now such as the BME280 and the Si7021.
@@rdagger I've spent more time on this than I'd like to admit. I started out the project on a RPi4, and was getting dht22 output readings from running dht_publish. At the point of running dht_subscribe on the Rpi it would appear successful, meaning no errors returned, but also no data and nothing on the lcd. Taking the same micro sd card I switched to the RPi3b+. Here I get errors from running dht_subscibe, but the lcd lights up with randomness - nothing legible. In both cases I test while physically connect to the esp32. I also test with independently powering the esp32 & dht22, however according to my router the esp32 is no longer connected to the wifi like it was when physically connect to the RPi. I don't believe the network settings are sticking when unplugged and independently powered.
@@nathankoops6203 The best approach would be to test the functionality 1 piece at a time in the repl. First open the repl on the ESP32 and see if you can successfully poll the DHT22 a few times. The first read often produces an error. Next see if you can publish an MQTT packet from the ESP32 repl and then subscribe and read the packet on the Pi in a terminal using the Mosquitto command line client.
@@rdagger I think what I'm missing is how to unplug the esp32 from the pi, independently power and still have repl running on boot and publishing. I'm getting the esp32 to network on boot, but not publish it would seem.
Normally you use a main.py file on the ESP32 to automatically connect to your WiFi access point. Then add a line at the end of this main.py file to run your MicroPython program. Here’s a template: from network import STA_IF, WLAN from machine import idle wlan = WLAN(STA_IF) wlan.active(True) nets = wlan.scan() for net in nets: ssid = net[0] if ssid == b'YOUR_SSID_HERE': wlan.connect(ssid, 'YOUR_PASSWORD_HERE') while not wlan.isconnected(): idle() # save power while waiting print('WLAN connection succeeded!') import YOUR_PROGRAM_HERE # Run your code break
This is awesome! Thanks for doing these videos! Extremely helpful for someone like me just getting started in microcontrollers. I’d really like to know if the esp32 can handle micropython + SSL/TLS in the mqtt communication as a basic security layer on top of a home’s WiFi). If so, this would the best of all worlds of Raspberry Pi, microcontrollers, Python, and IOT!Have you been able to (and/or are you interested in expanding this tutorial ) to get the esp32 running with micropython and communicate to mqtt broker via ssl/tls?
I haven't tried SSL but it should work. Here is some untested code: CLIENT_ID = ubinascii.hexlify(machine.unique_id()) SERVER = b'' USER = b'' PASSWORD = b'' client = MQTTClient(client_id=CLIENT_ID, server=SERVER, user=USER, password=PASSWORD, port=8883 ssl=True)
You shouod have neede certificates if you want to have a secure connection. If not, you only used TLS to set up an encrypted connection. Not a secured connection, which can't be taken over by Man In the Middle (MIM) attack.
This solution currently doesn't work. The software runs on both devices, but the ESP8266 wont connect with the Broker on the Pi. I will update if i find any solution to this.
The video is from 2017 and designed for an ESP32. Nonetheless, I just tested all the code using an ESP8266 and a Raspberry Pi 4 and the MQTT works great. I suspect you are having a networking or firewall issue. Adafruit did deprecate their Python SSD1306 OLED display driver so I added a code snippet to my website using Adafruit’s replacement display library.
rdagger68 none! it just went to the next line >>>> & nothing. will try the method in your web server video you made otherwise put it down to a faulty board.
You could have similar problem to the one I encountered in the video. Import network causes a current draw. An inadequate power supply, a low quality USB cable or a bad USB port could all be culprits.
I ran this project with a DHT-11 sensor under ubuntu environment and got these figures b'614, 1280' b'613, 1275' b'615, 1280' I didn't change any parameters and strictly followed the instructions. Can anyone tell me why the temperature was so high and the relative humidity exceeded 100%?
Make sure you specify DHT-11 instead of DHT-22 because they are not compatible. You can also try the LoBo build of MicroPython because it implements the DHT module using the ESP32 RMT peripheral. github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki
Thanks @@rdagger: After changing the three relevant statements to from dht import DHT11 CLIENT_ID = 'ESP32_DHT11..... sensor = DHT11(Pin(15.......... I got an error message "Invalid sensor readings" I just wonder if the mishap was caused by using different OS (Ubuntu instead of Raspberry Pi)
The ESP32 is reading the sensor so the Pi OS would not matter. I would take several readings because the DHT sensor will often give invalid readings. It could be a wiring issue. Are you using the 3 pin or 4 pin DHT-11? Are you using a pull-up resistor and if so what value? Make sure you keep your wires short.
@@rdagger There are only three pins in my DHT11 (+, out, -). I didn't add any resistor and all the wire was about 20cm in length. I try a similar project by using arduino "randomnerdtutorials.com/esp32-dht11-dht22-temperature-humidity-web-server-arduino-ide/" and the readings were perfect. That is to say, the hardware should be OK. Unfortunately, my esp32 board can't accept micropython commands after running the arduino project. Therefore, I've decided to give up. Anyway, thank you very much for your time.
rdagger68 , i dont understand, i havê inserted the code to pyboard but when i turn off the esp32 and connect only to eletric we do not send data to rasp via WiFi... Mosquito doesnt recieve anything
My problem is, when the ESP32 its connect to Raspberry i have no problem( i see the dht reading with mosquitto)...but i want to execute ( import network station = network.WLAN(network.STA_IF) station.active(True) station.connect("HUAWEI-E5172-0B47","A7RAG240M73") import dht_publish ) Every time the ESP boot to disconnect from the raspberry ... so my doubt is how esp32 boot my code without any usb connect to Raspberry? Thanks a Lot rdagger68 for the help
Unlike the ESP8266, the ESP32 does not remember network connections. You need to add a file called main.py which will automatically run when the ESP32 boots. Inside main.py you can add your code above to connect to the WiFi. There is an example in my next video: th-cam.com/video/xscBwC1SrF4/w-d-xo.html
I am having an error.please,help. >>> import dht_publish Traceback (most recent call last): File "", line 1, in File "dht_publish.py", line 11, in File "umqtt/simple.py", line 58, in connect OSError: [Errno 113] EHOSTUNREACH
I recommend you take a look at the LoBo MicroPython build which comes with an MQTT client that is more robust. I added an example to my website (at the bottom of the page): www.rototron.info/raspberry-pi-esp32-micropython-mqtt-dht22-tutorial/
@@rdagger thank you for the response. I had an earlier version of the *.bin . But i'm getting some unusual numbers on the T * H values. prntscr.com/oyx68k Again, thank you for your videos. They are very helpful and easy to follow
i am trying to setup my dht11 with esp8266 nodemcu and raspberry pi as MQTT broker. the problem is the following error: >>> sensor = DHT11(Pin(2, Pin.IN, Pin.PULL_UP)) Traceback (most recent call last): File "", line 1, in NameError: name 'DHT11' is not defined >>> import machine >>> from machine import Pin >>> from dht import DHT11 >>> >>> sensor = DHT11(Pin(2, Pin.IN, Pin.PULL_UP)) >>> sensor.measure() Traceback (most recent call last): File "", line 1, in File "dht.py", line 16, in measure OSError: [Errno 110] ETIMEDOUT >>> print(sensor.temperature()) 0 >>> i have it connected on D4(pin2). unfortunately i do not see any dht.py file. it is only dht_publish.py how can i fix that please?
I have found the MicroPython.org DHT code to be unreliable for the ESP8266. It's been a long time since I used an ESP8266. I primarily use the ESP32 and I'm using the LoBo build which has an excellent DHT library. Sorry I don't have any workarounds. I recommend you post your issue on forum.micropython.org/viewforum.php?f=16
Great tutorial - but it doesn't half seem a lot of resources to get a temperature and humidity reading. A simple ESP8266 and OLED display can do the same thing without breaking a sweat - AND send off the information elsewhere by MQTT - and a LOT more... I don't think we're putting the more expensive ESP32 to good use by comparison.
You have a good point but the video is a tutorial. The skills are applicable to more demanding scenarios. Also the Wemos Lolin32 is now around $6 and comes with a lithium battery charging circuit.
With forced respect, I disagree with the unfortunate criticism that follows after your first two words. (And who is the 'we' in "we're" anyway? Did you help make this video?) It's pretty clear by the use of the word "Tutorial"--and not something like 'ESP32 Bloodies ESP8266 in Epic Knockdown'--in the title that he's trying to help a general audience that includes beginners with micropython and/or the ESP32 and/or MQTT get started. That's great because there's not that much out there yet for micropython and the ESP32, because they're both relatively new. It wouldn't be all that great of a set of tutorial videos if he first didn't lay down a foundation of basics and he just posted some video showing off how complicated he could make something. That would take a lot of time and some trial and error to reverse engineer, and that's not really helpful for any kind of teaching style. Personally, I'm a beginner in all 3 of those categories, and after some basic research I chose to get started with an ESP32 because it's easy to see that the ESP32 is going to replace the ESP8266, the price is roughly the same in the Americas and in Europe, and it is not possible in a practical sense to implement AES/SSL in addition to hashing using the ESP8266 because of it's lower memory capacity (even with compiled Arduino code), which I suspect is one reason why the ESP32 has been developed in the first place. Relying on wifi security alone, even on a dedicated and isolated VLAN isn't enough for a large enough segment of the market--home or industry. Now if rdagger68 is able and willing to continue to make more of these pleasant and really great tutorials, I'm sure they'll eventually progress to a level that also happens to demonstrate something that wouldn't be so easy to do on the ESP8266 as you wish for--but it seems that that would be more of a coincidental fact than a focus. But you have a website too, so you can do the knockdown video.
m1carver I'd look at who you're addressing, Peter Scargill has more code for this on GIT hub than most other people so at least he is talking from a level of authority the neither you nor I have in this subject.
I think running micro Python on an ESP32 is a fairly heavy load just on its own but I guess it is more friendly for most. I look at the ESP32 as a replacement to the ESP8266, the cost difference is minor and the increased capabilities are worthwhile even if it is just for secure web connections or BLE or the low power processor.
I'm using a ESP8266 and still found the tutorial useful. I think even the most dimwitted of us, unexperienced in the topic, will know this are not the full capabilities of the ESP32 and the tutorial it's meant for teaching purposes.
Are you using a Raspberry Pi? If so, what version of Raspbian. Can you try a different computer? It could be a bad USB cable or jack. I could be a bad ESP32.
>>> import network >>> Does nothing so I looked it up for te ESP8266 and had to add the second line to >>> sta_if = network.WLAN(network.STA_IF) that workt.... I guess I got the today's version.. great tutorial...thanx edit: heyI made 100 typo's they are ok now but now I got these errors: file "dht_publish.py" line 26 in file "dht_publish.py" line 21 in
Hello... I am just getting started with Raspberry PI and ESP32. I came across your channel and am thoroughly impressed. Your content is awesome... 100% on point as it's precise, accurate and easily understood. Well done sir... 10 out of 10!
I respect that you understand and explain every piece of code you take from the web. I learned a lot since the beginning of this series on esp32.
You speak very fast but very clear. Really helpful video.
This is awsome as to me helped me learn a lot thanks
Yeah. He's excellent!
Thanks for the tutorial, loved your pace of delivery and lack of waffle. It would be great to see several sensors collecting data, with time-date stamps when the sensor readings were captured, sending these to a data log on the Pi.
Thanks for this tutorial. As a beginner, it covered the basics which really helped me get my ESP8266 up and running as a MQTT client. I really appreciate your hard work putting this together. thanks!
Your video clips are great.
Very helpful are the links to the written tutorials. These help a lot when one is a beginner to this matter and when one does not speak English fluently (you speak a bit fast).
Please carry on with uploading such interesting tutorials, thanks.
Bring the speed down to .75 in the settings. Helps me too and my native language is English!
Love the videos! It has been said before, but I really appreciate your efforts!
Again,great video...learnt a lot of things👍
A very USEFUL tutorial! Thank you very much for your time to do it!
Great work! I like the python work.
Thank you so much from South Korea
Really grate videos! They help me a lot!
Very Nicely explained. Do make more video on this using multiple esp32 n pi as broker
Really learnt a lot, very well presented. thanks
Really great tutoria! Thanks a lot for sharing!🙏👏👏👏👏👏👏😁
I learned a lot from this video. Thank you!
very nice video and easy to follow along great work thank you
Interesting stuff, thanks!
Amazing Explanation...Is it neceassary to make use of breadboard for the connections? can we directly connect DHT22 with ESP32 using F-F jumper cables?
You can connect directly. Shorter wires work better.
thanks a lot, nice tutorial
great video, very well explained.
About the wifi issue on esp32 board, I had exactly same issue when importing the network module. Have you done any further troubleshooting or found a way to correct it ? For now I'm proceeding with a different board as well, but I was wondering if defected one could be fixed.
Thanks!
It's a gamble buying generic ESP32 boards on eBay. They often have bad soldering and use rejected parts. I think the only problem is the defective micro-USB port. The board would probably be fine if I replaced it. One work-around is to connect the Pi's 5V pin directly to the ESP32's 5V pin and connect the grounds. This should protect against brown outs caused by a shoddy USB port or cable. Since switching to the Wemos Lolin32, I have not encountered any problems.
Great job thank you
Nice tutorial, thanks. I don't run Unix so adapted what you were doing to the Thonny IDE which I have just loaded (looks quite good). My second sketch (?) after doing a blink one.
Had to modify one line to include port (not sure it was necessary), user and password for the Mosquito broker running on a Pi under Home Assistant...
client = MQTTClient(CLIENT_ID, SERVER, port=1883, user=b"username", password=b"password")
I tried adding them in the simple.py program but that didn't work! Still lots to learn,
I can see it's working by using MQTT Explorer on my PC.
I like your video's. They are very helpful and understandable. I want though, the same video's with NodeMcu esp8266 if possible. Please cover topic with 2 ore more switches and relays as well. Thanking in advance.
Wonderful video for a beginner like me. I've got a question. How would you add a display to the sensor board so that you could monitor the temp/hum at the site? That would be extremely handy.
The same OLED display could be used on the ESP32. I have a video on color OLED displays: th-cam.com/video/a7DrFqqu-78/w-d-xo.html
You should also look at the LoBo build because it comes with a very robust display library: github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki
LoBo has recently added support for FTDI EVE displays which are very powerful.
@@rdagger Thanks so much for the reply ! I'm kind of new to this. Took Fortran about a million years ago and never programmed again until I bought a Pi and am trying to learn Python and Debian. I just found your channel and I love how detailed you are and how fast you pull a project together. Your website is next.
I have dozens of ideas to investigate from automating a whole house wood stove to signal and brake lights on an RC truck. Also kodi and a cloud server, security cameras and hydroponics.
I am somewhat overwhelmed with all the information available and how fast it is changing but that is half the fun. Between the piles of books, online courses, TH-cam and adafruit I don't know where to start. Linux is new to me and I am well past my optimum learning years so I have my work cut out.
Again, thanks for the reply. You will be hearing more from me.
Great video, thank you.
You can press Ctrl+L to clear terminal instead of typing clear. What is the approximate system load on the Raspberry Pi ? Could you possibly run htop while the MQTT is running?
I use the clear commands as markers when I'm editing the video. Also my pace is very fast so I try to avoid keyboard shortcuts, command history and tab completion to make it easier to follow.
Mosquitto is very lightweight. I don’t have anything currently set up to test the resources properly. Just starting the broker has the follow results;
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
1202 mosquitto 20 0 8776 4744 4260 S 0.0 0.2 0:00.28 /usr/sbin/mosqu
@@rdagger
Thanks for quick reply, You can use htop to monitor system resources in runs from a terminal. Install with sudo apt install htop
To run, open a new terminal and type 'htop' to monitor your system.
The difference is you get a CPU useage graph for each core and use of colour easier to read than top.
Love your videos. Can u make video on micropython+esp32+rapberrypie+node red
awesome videos very easy to learn from. have you done any work with wireless packet injection in micro python?
Thanks! I have not experimented with packet injection. There was a relevant thread on the MicroPython forum: forum.micropython.org/viewtopic.php?f=16&t=3389
I think that if you put a 4 sec wait before first reading, it might work better when starting in the beginning?
You should propably post temperature and humidity on different subjects. And voltage level are also good to have posted through MQTT so users knows when to change batteries.
mDNS would also be a good way to connect the MQTT server without knowing its IP address.
And yes, great tutorial, thanks.
Good points. I know the IDF supports mDNS, but I'm not sure if MicroPython has implemented it yet.
Thanks for the feedback!
rdagger68 many home routers also uses DHCP to set the name used by the device to register as solvable name through its DNS.
Would be greate if more computers uses mDNS.
Excellent
Hi, please share the link for this project's code and it is not there in the above link shown. Thank you.
The link is in the video description. I just tested it, and it works. You may have to scroll or click the arrow to see the full description.
@@rdagger Ok, I will try again, thank you.
So very good, i wil make this to. :)
Hello excellent video, I am building something similar to your example, I use the Lolin32 and a max31865 for a temperature sensor. I have a question: what kind of library or code do I need to connect the MAX31865 to the esp32? I'm a total beginner so if you could give me step vy step advice I would appreciate, Thank you.
I haven’t used the MAX31865 but there is a MicroPython ESP32 library for it on GitHub:
github.com/htlb-atk/schilf-iot-MAX31865
The library has excellent documentation (German):
htlb-atk.github.io/schilf-iot-MAX31865/
Thank you!
Very good.!
You can use Adafruit libraries on microphython? I thought they were circuitphython onl.
The SSD1306 display is connected to the Raspberry Pi, which is running Python 3 code (not MicroPython). The Adafruit SSD1306 driver is a Python 3 library designed for the Raspberry Pi and Beaglebone Black. One of the great features of MQTT is that it allows communication between systems running different programming languages.
rdagger68 my bad. Thanks. I have a PI 0w and a 4 I could do the same.
Does MQTT automagically store the data somewhere, or would you have to write a script to capture the topic data to save it?
As far as I know, Mosquitto does not provide any built-in mechanism to save MQTT data into a database. Try a Google search for mosquitto database
Nice job!
Hey i have another doubt
At 7:12 we have the data being converted to the byte format
My question may sound silly but i would like to know if that works for all sensors or just for DHT specifically (i e,can i convert the data from any sensor to the byte format using this syntax or is there any other specific syntax)
It's not DHT specific but I think that the latest version of Python no longer supports using the format method with the bytes type. However, if you wanted to achieve the same bytes conversion, you could use the following if formatting is necessary:
msg = f'{t:3.1f},{h:3.1f}'.encode('utf-8')
@@rdagger Thank you so much...i will try it out👍
Hi to all, this tutorial was great and very helpful, thank you very much.
A quick question from you expert guys, Can I connect a Temperature Sensor which uses resistance (milliOhm) as its output? or in another word does the ESP32 or other series of ESP... take resistance input in any of its pins (GPIOs, etc.)? more clarification is: currently my resistance temperature sensors are connected to a I/O card that follows Resistance Temperature Detector (RTD) and receives the changes in the resistance of the temperature sensor and I wanted to make the temp. sensors wireless with utilizing ESP... .
Yes you can measure resistance using the analog pins on the ESP32. You can do this by creating a voltage divider comprised of 2 resistors. The first resistor is your variable resistance source (a sensor that varies resistance). The second resistor is a fixed value (close to the range of your sensor). As the sensor changes resistance the voltage output of the divider will vary and the ESP32 analog pin can measure it. UNFORTUNATELY, most RTD sensors require a very high quality amplifier such as a MAX31865 RTD-to-Digital converter. I think Adafruit sells a MAX31865 breakout board that can be connected to the ESP32 using SPI protocol.
In my 4th video of this series, I show how to connect and measure a SoftPot using the analog pins on the ESP32. A SoftPot is a potentiometer which is a voltage divider.
th-cam.com/video/a7DrFqqu-78/w-d-xo.html
Thanks a lot for all the valuable info. I will try them and if I stuck anywhere i will bother you with question. Very helpful channel, cheers!
Hi again rdagger68, I have discussed what you said with our electrical technician, but he was rather confused, can you provide drawing or diagram of this circuit (if it is not too much to ask) ? (email: babaknasiri36@gmail.com)
Generally speaking, an RTD sensor requires a very high quality amplifier such as the MAX31865: www.adafruit.com/product/3328
Therefore, a simple voltage divider approach would not be sufficient. A voltage divider could be used with thermistor as in this Arduino example: learn.adafruit.com/thermistor/using-a-thermistor
Is it possible to use an ESP32 to do a PWM from analog inputs to a PPM output string? A radio control receiver needs to read the PPM transmitted over the air which it then parses out the individual channels (PWM from the analog inputs) from the PPM string (frame) to send to the corresponding servo. There's a delay at the end that signals the end of the PPM frame which tells the receiver to get ready for the next frame. What I would like to do is take each analog input and convert it into an 11bit value between .9 and 2.1ms and make a PWM signal. There would be 6 channels and each PPM frame would be 20ms total. So the max would be 2.1x6=12.6ms for all channels(PWM values) + (20-12.6, the delay period) = 20ms total. The PPM frame is output from the ESP to an RF deck which would transmit it to the receiver. It would need to output the PPM signal at at least 50hz preferably 60. I know this can be done with an Arduino but these seem smaller and it would be cool to have an option.
Reading the ADC inputs should be no problem using the ADC class.
The PPM is more difficult.
There are existing libraries for decoding ppm: github.com/dastultz/micropython-ppm-decoder & github.com/jeffeb3/cppm_micropython
I haven’t seen any MicroPython encoding libraries. I haven’t worked with ppm. I assume you need to generate waveforms. The ESP32 hardware should be able to accomplish this but I don’t know if MicroPython affords the necessary control. You can create analog waves using the DAC class: micropython-docs-esp32.readthedocs.io/en/esp32_doc/library/pyb.DAC.html and the LoBo build has a DAC module that might work: github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/dac
I suggest you post your question to the MicroPython forum: forum.micropython.org/
i put import prog in boot.py but how to keep the prog going on as when you quit repl (Ctrl-x) and rshell (Ctrl-d), the program stops !
The program should continue to run after you exit rshell. You can always press the reset button to restart your program. I'd run your program from main.py instead of boot.py.
Hi, your tutorials are really excellent, thanks for doing that. We're using ESP32 as "motes" sending MQTT data to Node-RED on a Pi, so your instructions are right on. But did you know your website seems to be down? Best Regards, A
Thanks. Sorry there's a power outage. The site should be back up in 12 hours.
Website is back online.
You can also just do Downloads/esp then press tab and it should auto complete the file name if you want to avoid the annoying process of copy paste in terminal.
I get that a lot but my pace is very fast so I try to avoid keyboard shortcuts, command history and tab completion to make it easier to follow.
@@rdagger Sure thing. I think it makes sense for the video, but incase others reading the comments wanted to be a little faster.
Hello. It is necessary to put a delay in client code to transmit the data? What will happen if i didnt put some delay? What is the minimum delay if it is required?
Your tutorials are fantastic.Thank you for them.I am stuck on the "import network" part. Nothing happens when I run this command in repl. Do you know where the problem might be ?
What happens after you type import network? Does the REPL freeze or do you get an error message?
After I type import network ,nothing happens. When I hit enter I just get >>> .So REPL is not frozen ,I am just not getting any information on screen.When you type " import network" in the video ,a lot of information is printed on screen starting with wifi firmware version.
Your build might have the debugging messages turned off.
Does your boot.py file contain the line esp.osdebug(None), this would turn off the messages?
You can try manually turning on the debugging messages by typing the following before the import network statement:
import esp
esp.osdebug(0)
Also if you plugged anything into UART0, you should remove it first.
I am getting this . Do you have any ideas what could be wrong ? I have 2 boards and the same problem with both. >>>
>>>
>>> import network
>>> station = network.WLAN(network.STA_IF)
I (108515) wifi: wifi firmware version: 111e74d
I (108515) wifi: config NVS flash: enabled
I (108515) wifi: config nano formating: disabled
I (108515) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (108525) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (108545) wifi: Init dynamic tx buffer num: 32
I (108545) wifi: Init data frame dynamic rx buffer num: 64
I (108545) wifi: Init management frame dynamic rx buffer num: 64
I (108555) wifi: wifi driver task: 3ffe1620, prio:23, stack:4096
I (108555) wifi: Init static rx buffer num: 10
I (108565) wifi: Init dynamic rx buffer num: 0
I (108565) wifi: Init rx ampdu len mblock:7
I (108575) wifi: Init lldesc rx ampdu entry mblock:4
I (108575) wifi: wifi power manager task: 0x3ffe854c prio: 21 stack: 2560
W (108585) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
Brownout detector was triggered
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled.
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4332
load:0x40078000,len:0
load:0x40078000,len:10992
entry 0x4007a6c4
W (66) rtc_clk: Potentially bogus XTAL frequency: 35 MHz, guessing 40 MHz
I (357) cpu_start: Pro cpu up.
I (357) cpu_start: Single core mode
I (357) heap_init: Initializing. RAM available for dynamic allocation:
I (361) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (367) heap_init: At 3FFDCE10 len 000031F0 (12 KiB): DRAM
I (373) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (379) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (386) heap_init: At 40090060 len 0000FFA0 (63 KiB): IRAM
I (392) cpu_start: Pro cpu start user code
I (186) cpu_start: Starting scheduler on PRO CPU.
OSError: [Errno 2] ENOENT
MicroPython v1.9.3-332-g27fa9881 on 2018-02-19; ESP32 module with ESP32
Type "help()" for more information.
>>>
Since the Brownout detector was triggered, I think you have a power issue. The Wi-Fi module draw a lot of power when activated. The are several possibilities: 1. Power supply is too weak, 2. USB cable too long or thin, 3. USB jack on the ESP32 is defective, 4. You have additional components connected to the GPIO pins that are drawing too much current.
Do you have any idea of how much the update data time can be reduced? also, is it possible to use a ESP 8266 instead of ESP32?
i have a doubt. When i type import network after opening repl, it doesn't show anything it just come down to below line
That’s what’s supposed to happen.
All Great! Would like to seea video on ESP32 with an Android app that dispalys a value and has ability to set value in ESP32.
Please keep using the RPi with Micro Python onthe ESP32.
Hi, how i can automatizate the proccess to load de Script file since rpi?
A basic question. Since the ESP32 has wifi, is it possible to set it up so that it connects to wifi automatically on power up and then runs the micropython code to publish the data. It seems to me that if the only way is to keep it connected to the Raspberry Pi, then that defeats the purpose, somewhat. Ideally, one could have the rshell running remotely over wifi to connect. I don't have an ESP32 but was thinking of getting one.
ETA: just saw your next video which has the main.py
Still remaining: can rshell connect remotely?
In the 6th video of this series I demonstrate the LoBo build of MicroPython which comes with built-in FTP, Telnet and mDNS. This affords wireless REPL access and file management.
With respect to Rshell, it might be possible to set up wireless serial communication but I don't know. You could ask Dave the creator of Rshell: github.com/dhylands/rshell
Thank you. This looks to be a great series. I have only finished the first two.
ETA: It also appears that webrepl for ESP32 is also available in the following fork: github.com/Hermann-SW/webrepl
From: forum.micropython.org/viewtopic.php?f=2&t=3124&p=30434&hilit=esp32#p30434
Can I transmit this data to my iphone? Thanks! Ken
There are MQTT apps for iPhone and Android. I also have MicroPython videos that demonstrate a web server and web sockets for the ESP32.
th-cam.com/video/xscBwC1SrF4/w-d-xo.html
th-cam.com/video/uzY6aSg9Ly8/w-d-xo.html
I can’t connect to the REPL, used your tutorial, downloaded different files from micropython, was able to erase and flash... any ideas?
error message? did you flash to starting address 0x1000?
Does both the raspberrypi and ESP32 need to be on the same network?
Their networks have to be able to speak to each other. For different networks you would need to be able to bridge them. For example, you could set up a VPN between the networks. If you are looking for a remote solution, you should check out ThingSpeak.com. The LoBo build of MicroPython has a built-in MQTT library with support for ThinkSpeak: github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/mqtt#example-connecting-to-thingspeak
Thanks for the video. Same thing I want to do using the ESP8266 (Esp-12E). i have followed the steps of this video. after reaching : "rshell --buffer-size -p /dev/ttyUSB0". it shows connect to REPL. and then give some errors. Please guide me in this regard. Thanks
You omitted the buffer-size value.
Great tutorial, easy to follow and copy command lines from your website. I have got some error message when running: import dht_publish
Here is what I got returned:
Traceback (most recent call last):
File "", line 1, in
File "dht_publish.py", line 11, in
File "umqtt/simple.py", line 99, in connect
MQTTException: 5
Not sure how to proceed further. Line 11 in dht_publish is attempting to connect to mqtt server. I have adjusted IP address to match my RPI address. I haven't done any changes to simple.py file. My Mosquitto server is running, I am able to send message and receive it using Node Red, as well as command line in Putty, so I am not sure what else can I check and change.
I just re-tested the dht_publish code and it's working OK. Are you sure your ESP32 is connected to your Wi-Fi network?
btw: youtube flags any comment with .py as SPAM because it thinks it is a hyperlink to Paraguay.
quick question: as your mqtt pub micropython code requires the server number (the IP address of the broker; in this case RasPI), isn't it essential that the raspberry pi is set up with a static IP address? (if the Pi reboots then the IP address may be dynamically changed by the wifi router)
I more reliable method would be to use mDNS. I recommend you check out the Loboris build because it comes loaded with MQTT and mDNS. My next video will probably cover mDNS.
github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki
thanks, I had better read up a little on what mDNS is!! thanks for the advice to shift to the Loboris build too.
Hey great video!!!Everything went on just perfect until I came to the command Mosquitto_sub -d -t "TOPIC_NAME". upon executing this command I get this output
Client (null) receiving connect
Client(null) receiving Connack (0)
Client (null) sending SUBSCRIBE (Mid: 1,Topic:"TOPIC_NAME",QoS: 0,Options:0x00)
Subscribed (mid: 1): 0
Client(null) sending PINGREQ
Client(null) received PINGRESP
and the last 2 statements keep getting printed until I force quit using ^C. I have searched far and wide for a possible explanation but none of the solutions seem to work out. Could you please help?
and moreover import "FILENAME" gives me this
File "dht_publish.py", line 10, in
File "umqtt/simple.py", line 68, in connect
OSError: [Errno 104] ECONNRESET
Could you please help?
Mosquitto v.2.0 restricts access to the localhost only be default. Modifications are required to the mosquitto.conf file which is located in the /etc/mosquitto directory. Append the 2 following lines to the .conf file to allow remote computers to access the Mosquitto broker without authentication:
listener 1883 0.0.0.0
allow_anonymous true
@@rdagger thank you so much!! Along with this i also found that my mobile hotspot took over the ipv6 address instead of ipv4. Adding these two lines and changing my wifi did the trick..Thanks again!
Hi rdagger68 - I can't import the umqtt module, I get the error "ImportError: no module named umqtt" - any ideas?
Ooooh - I just realised I totally missed the bit on the module import - derp!!
Hi, thanks for the tutorial help me a lot. I havê a tricky problem when the internet restart i loose the connection to esp32 there is any solution for this? Can someone help me?
Does the problem occur when you restart your Internet router? I assume you are losing the MQTT connection, correct?
rdagger68 , Hi yes when i restart the router i enter on raspberry and whe. I put mosquito he doesnt show anyhting on output...i need to restart DHT to see again temperature. The connection is via WiFi raspberry to DHT.
On the ESP32 you can check your Wi-Fi connection with the network library:
from network import STA_IF, WLAN
station = WLAN(STA_IF)
Then you can wrap the publish statement to ensure it is connected:
if station.isconnected():
client.publish(TOPIC, msg)
else:
print('Lost Wi-Fi connection.')
I had a similar problem make sure your PI is getting 2.5 -3.0 amps from wall-wart
Hi, I have a question, how to make another ESP32 subscribe to topic and go over the data.
It is very similar to the publishing code. There are subscribe examples on the MicroPython Lib repo: github.com/micropython/micropython-lib/tree/master/umqtt.simple
Thank you for the quick response, one more question, I checked one of the example from the website, so all I have to do is change the local host to raspberry pi IP address and the topic to the topic that I want to subscribe for example the dht_publish topic ?
Hi, all it's perfects. But, how assign IP address if I have dinamycle IP assign?
You should be able to reference the Pi by host name instead of by IP.
Can I replace esp32 to esp8266 for this project ?
I have not tested it. The ESP8266 has less memory than the ESP32 but it is probably enough to run this simple project.
Is this project still supported? I've been successful with everything except to the very last bit of running dht_subscribe. Still providing help? This is my first exposure to mqtt. If I'm successful I'd like to esp32 the heck out of many things :)
I tested the code from the video last week on an ESP8266 and it worked. You may have received a bad DHT22 especially if you purchased from eBay or Ali Express. It could also be a wiring issue. Make sure you keep the wires as short as possible. There are many more reliable temperature / humidity sensors available now such as the BME280 and the Si7021.
@@rdagger I've spent more time on this than I'd like to admit. I started out the project on a RPi4, and was getting dht22 output readings from running dht_publish. At the point of running dht_subscribe on the Rpi it would appear successful, meaning no errors returned, but also no data and nothing on the lcd.
Taking the same micro sd card I switched to the RPi3b+. Here I get errors from running dht_subscibe, but the lcd lights up with randomness - nothing legible.
In both cases I test while physically connect to the esp32. I also test with independently powering the esp32 & dht22, however according to my router the esp32 is no longer connected to the wifi like it was when physically connect to the RPi. I don't believe the network settings are sticking when unplugged and independently powered.
@@nathankoops6203 The best approach would be to test the functionality 1 piece at a time in the repl. First open the repl on the ESP32 and see if you can successfully poll the DHT22 a few times. The first read often produces an error. Next see if you can publish an MQTT packet from the ESP32 repl and then subscribe and read the packet on the Pi in a terminal using the Mosquitto command line client.
@@rdagger I think what I'm missing is how to unplug the esp32 from the pi, independently power and still have repl running on boot and publishing. I'm getting the esp32 to network on boot, but not publish it would seem.
Normally you use a main.py file on the ESP32 to automatically connect to your WiFi access point. Then add a line at the end of this main.py file to run your MicroPython program. Here’s a template:
from network import STA_IF, WLAN
from machine import idle
wlan = WLAN(STA_IF)
wlan.active(True)
nets = wlan.scan()
for net in nets:
ssid = net[0]
if ssid == b'YOUR_SSID_HERE':
wlan.connect(ssid, 'YOUR_PASSWORD_HERE')
while not wlan.isconnected():
idle() # save power while waiting
print('WLAN connection succeeded!')
import YOUR_PROGRAM_HERE # Run your code
break
This is awesome! Thanks for doing these videos! Extremely helpful for someone like me just getting started in microcontrollers. I’d really like to know if the esp32 can handle micropython + SSL/TLS in the mqtt communication as a basic security layer on top of a home’s WiFi). If so, this would the best of all worlds of Raspberry Pi, microcontrollers, Python, and IOT!Have you been able to (and/or are you interested in expanding this tutorial ) to get the esp32 running with micropython and communicate to mqtt broker via ssl/tls?
I haven't tried SSL but it should work. Here is some untested code:
CLIENT_ID = ubinascii.hexlify(machine.unique_id())
SERVER = b''
USER = b''
PASSWORD = b''
client = MQTTClient(client_id=CLIENT_ID,
server=SERVER,
user=USER,
password=PASSWORD,
port=8883
ssl=True)
You shouod have neede certificates if you want to have a secure connection. If not, you only used TLS to set up an encrypted connection. Not a secured connection, which can't be taken over by Man In the Middle (MIM) attack.
This solution currently doesn't work. The software runs on both devices, but the ESP8266 wont connect with the Broker on the Pi. I will update if i find any solution to this.
The video is from 2017 and designed for an ESP32. Nonetheless, I just tested all the code using an ESP8266 and a Raspberry Pi 4 and the MQTT works great. I suspect you are having a networking or firewall issue. Adafruit did deprecate their Python SSD1306 OLED display driver so I added a code snippet to my website using Adafruit’s replacement display library.
Hi great video everything went great until the import network in repl it does not list network :( but help() shows it's there grrrr.
What command are you using? What error message to you get?
rdagger68 none! it just went to the next line >>>> & nothing. will try the method in your web server video you made otherwise put it down to a faulty board.
You could have similar problem to the one I encountered in the video. Import network causes a current draw. An inadequate power supply, a low quality USB cable or a bad USB port could all be culprits.
Successfully connected to Wifi using the main.py method, thanks for all your helpful advice & videos.
I ran this project with a DHT-11 sensor under ubuntu environment and got these figures
b'614, 1280'
b'613, 1275'
b'615, 1280'
I didn't change any parameters and strictly followed the instructions. Can anyone tell me why the temperature was so high and the relative humidity exceeded 100%?
Make sure you specify DHT-11 instead of DHT-22 because they are not compatible. You can also try the LoBo build of MicroPython because it implements the DHT module using the ESP32 RMT peripheral.
github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki
Thanks @@rdagger:
After changing the three relevant statements to
from dht import DHT11
CLIENT_ID = 'ESP32_DHT11.....
sensor = DHT11(Pin(15..........
I got an error message "Invalid sensor readings"
I just wonder if the mishap was caused by using different OS (Ubuntu instead of Raspberry Pi)
The ESP32 is reading the sensor so the Pi OS would not matter. I would take several readings because the DHT sensor will often give invalid readings. It could be a wiring issue. Are you using the 3 pin or 4 pin DHT-11? Are you using a pull-up resistor and if so what value? Make sure you keep your wires short.
@@rdagger There are only three pins in my DHT11 (+, out, -). I didn't add any resistor and all the wire was about 20cm in length. I try a similar project by using arduino "randomnerdtutorials.com/esp32-dht11-dht22-temperature-humidity-web-server-arduino-ide/" and the readings were perfect. That is to say, the hardware should be OK. Unfortunately, my esp32 board can't accept micropython commands after running the arduino project. Therefore, I've decided to give up. Anyway, thank you very much for your time.
How i insert the code permanent to ESP32?
Do you need instructions on how to upload the firmware? If so, please check out my prior video: th-cam.com/video/w15-EQASP_Y/w-d-xo.html
rdagger68 , i dont understand, i havê inserted the code to pyboard but when i turn off the esp32 and connect only to eletric we do not send data to rasp via WiFi... Mosquito doesnt recieve anything
My problem is, when the ESP32 its connect to Raspberry i have no problem( i see the dht reading with mosquitto)...but i want to execute (
import network
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect("HUAWEI-E5172-0B47","A7RAG240M73")
import dht_publish )
Every time the ESP boot to disconnect from the raspberry ... so my doubt is how esp32 boot my code without any usb connect to Raspberry? Thanks a Lot rdagger68 for the help
Unlike the ESP8266, the ESP32 does not remember network connections. You need to add a file called main.py which will automatically run when the ESP32 boots. Inside main.py you can add your code above to connect to the WiFi. There is an example in my next video: th-cam.com/video/xscBwC1SrF4/w-d-xo.html
I am having an error.please,help.
>>> import dht_publish
Traceback (most recent call last):
File "", line 1, in
File "dht_publish.py", line 11, in
File "umqtt/simple.py", line 58, in connect
OSError: [Errno 113] EHOSTUNREACH
The connection might be failing because your Wi-Fi is not
ready. Try adding a line to test if the
Wi-Fi is connected prior to the MQTT connection.
I recommend you take a look at the LoBo MicroPython build which comes with an MQTT client that is more robust. I added an example to my website (at the bottom of the page): www.rototron.info/raspberry-pi-esp32-micropython-mqtt-dht22-tutorial/
Failed to read sensor. Would anyone help me?
Try posting your question to the MicroPython forum and include your code and pics of the wiring: forum.micropython.org
i hate to bother. but I cant get "import network" to work. I've read this and that...I've gotten NOWHERE...any ideas?
Without an error message, I don't have much to go on.
@@rdagger thank you for the response. I had an earlier version of the *.bin . But i'm getting some unusual numbers on the T * H values. prntscr.com/oyx68k
Again, thank you for your videos. They are very helpful and easy to follow
i am trying to setup my dht11 with esp8266 nodemcu and raspberry pi as MQTT broker. the problem is the following error:
>>> sensor = DHT11(Pin(2, Pin.IN, Pin.PULL_UP))
Traceback (most recent call last):
File "", line 1, in
NameError: name 'DHT11' is not defined
>>> import machine
>>> from machine import Pin
>>> from dht import DHT11
>>>
>>> sensor = DHT11(Pin(2, Pin.IN, Pin.PULL_UP))
>>> sensor.measure()
Traceback (most recent call last):
File "", line 1, in
File "dht.py", line 16, in measure
OSError: [Errno 110] ETIMEDOUT
>>> print(sensor.temperature())
0
>>>
i have it connected on D4(pin2). unfortunately i do not see any dht.py file. it is only dht_publish.py how can i fix that please?
I have found the MicroPython.org DHT code to be unreliable for the ESP8266. It's been a long time since I used an ESP8266. I primarily use the ESP32 and I'm using the LoBo build which has an excellent DHT library. Sorry I don't have any workarounds. I recommend you post your issue on forum.micropython.org/viewforum.php?f=16
Great tutorial - but it doesn't half seem a lot of resources to get a temperature and humidity reading. A simple ESP8266 and OLED display can do the same thing without breaking a sweat - AND send off the information elsewhere by MQTT - and a LOT more... I don't think we're putting the more expensive ESP32 to good use by comparison.
You have a good point but the video is a tutorial. The skills are applicable to more demanding scenarios. Also the Wemos Lolin32 is now around $6 and comes with a lithium battery charging circuit.
With forced respect, I disagree with the unfortunate criticism that follows after your first two words. (And who is the 'we' in "we're" anyway? Did you help make this video?) It's pretty clear by the use of the word "Tutorial"--and not something like 'ESP32 Bloodies ESP8266 in Epic Knockdown'--in the title that he's trying to help a general audience that includes beginners with micropython and/or the ESP32 and/or MQTT get started. That's great because there's not that much out there yet for micropython and the ESP32, because they're both relatively new. It wouldn't be all that great of a set of tutorial videos if he first didn't lay down a foundation of basics and he just posted some video showing off how complicated he could make something. That would take a lot of time and some trial and error to reverse engineer, and that's not really helpful for any kind of teaching style. Personally, I'm a beginner in all 3 of those categories, and after some basic research I chose to get started with an ESP32 because it's easy to see that the ESP32 is going to replace the ESP8266, the price is roughly the same in the Americas and in Europe, and it is not possible in a practical sense to implement AES/SSL in addition to hashing using the ESP8266 because of it's lower memory capacity (even with compiled Arduino code), which I suspect is one reason why the ESP32 has been developed in the first place. Relying on wifi security alone, even on a dedicated and isolated VLAN isn't enough for a large enough segment of the market--home or industry. Now if rdagger68 is able and willing to continue to make more of these pleasant and really great tutorials, I'm sure they'll eventually progress to a level that also happens to demonstrate something that wouldn't be so easy to do on the ESP8266 as you wish for--but it seems that that would be more of a coincidental fact than a focus. But you have a website too, so you can do the knockdown video.
m1carver I'd look at who you're addressing, Peter Scargill has more code for this on GIT hub than most other people so at least he is talking from a level of authority the neither you nor I have in this subject.
I think running micro Python on an ESP32 is a fairly heavy load just on its own but I guess it is more friendly for most.
I look at the ESP32 as a replacement to the ESP8266, the cost difference is minor and the increased capabilities are worthwhile even if it is just for secure web connections or BLE or the low power processor.
I'm using a ESP8266 and still found the tutorial useful.
I think even the most dimwitted of us, unexperienced in the topic, will know this are not the full capabilities of the ESP32 and the tutorial it's meant for teaching purposes.
'dmesg | grep ttyUSB' won't give anything back!? Ideas?
Are you using a Raspberry Pi? If so, what version of Raspbian. Can you try a different computer? It could be a bad USB cable or jack. I could be a bad ESP32.
Thanks for your quick reply rdagger68. Yeah using RPi/Jessie... It was indeed the USB cable!
>>> import network
>>>
Does nothing so I looked it up for te ESP8266 and had to add the second line to
>>> sta_if = network.WLAN(network.STA_IF)
that workt....
I guess I got the today's version..
great tutorial...thanx
edit:
heyI made 100 typo's they are ok now but now I got these errors:
file "dht_publish.py" line 26 in
file "dht_publish.py" line 21 in