I recently purchased the MicroPython ESP32 ebook.
On one of the Random Nerd websites (DS18B20) an example is given using MicroPython to create a webserver for the temperature display.
I would like to assign a fixed (static) IP address to the code. The current code gets the IP address from the DHCP server, and time and again the address changed.
I have tried to add the following line just after the line
station.active(True) station.ifconfig('192.168.100.205','255.255.255.0','192.168.100.2','8.8.8.8')
BUT, no matter in what format I enter the station.ifconfig….. information, the moment I add that line, the compiler fails with errors.
I am using Thonny, as uPyCraft does not want to connect to the ESP32 unless I do a firmware download each time.
Could you possibly give example code on how to setup a static IP address using micropython for an ESP32?
Thanks
Hi Jacques,
We don’t have any example about static ip address with MicroPython.
But can you tell me the errors you’re getting?
Note that the ifconfig function should accept a tuple.
So, I think that if you use the following line instead (with double parentheses), it should work:
station.ifconfig(('192.168.100.205','255.255.255.0','192.168.100.2','8.8.8.8'))
See in this discussion: https://forum.micropython.org/viewtopic.php?t=2378
Let me know if this solves your issue.
Regards,
Sara
Hi Sara,
I had the line in both single and double quotes (tuple) but neither of them worked.
This morning I flashed my ESP32 with the latest and greatest available firmware, (esp32-idf3-20191202-v1.11-611-g7f24c2977.bin) and there you go, problem solved.
I hope I can get all my other modifications done before I hit the next obstacle.
Thank you