How to program esp8266 to connect to wifi

Thread Starter

quique123

Joined May 15, 2015
389
If I connect an Esp8266 to a battery and dht sensor, how would I program the esp8266 to be configurable by a user to connect to a wifi?

Iow, when it is powered up by th user by plugging in a battery, how could he configure the module to connect to a local wifi?
 

Thread Starter

quique123

Joined May 15, 2015
389
ok i got the wifiManager library and ArduinoJSON library on my IDE. I tried uploading the sketch from Example #1 here:

https://randomnerdtutorials.com/wifimanager-with-esp8266-autoconnect-custom-parameter-and-manage-your-ssid-and-password/

but I get an error when uploading:
Code:
esptool.py v2.6
2.6
esptool.py v2.6
Serial port /dev/cu.wchusbserialfd120
Connecting......
Chip is ESP8266EX
Features: WiFi
MAC: 5c:cf:7f:a3:f9:99
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 1MB
Flash params set to 0x0320
Compressed 261248 bytes to 190878...

Writing at 0x00000000... (8 %)Traceback (most recent call last):
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/upload.py", line 25, in <module>
    esptool.main(fakeargs)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 2698, in main
    operation_func(esp, args)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 2158, in write_flash
    esp.flash_defl_block(block, seq, timeout=DEFAULT_TIMEOUT * ratio * 2)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 104, in inner
    return func(*args, **kwargs)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 632, in flash_defl_block
    self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 354, in check_command
    val, data = self.command(op, data, chk, timeout=timeout)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 332, in command
    p = self.read()
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 277, in read
    return next(self._slip_reader)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 1889, in slip_reader
    raise FatalError('Invalid head of packet (0x%s)' % hexify(b))
esptool.FatalError: Invalid head of packet (0x00)
esptool.FatalError: Invalid head of packet (0x00)
the wiring is:
ESP-Nano
Tx------Tx
Rx------Rx
G-------G
Vcc-----3.3V
EN---10k---3.3V
GPIO0---NC (only when plugging in the 3.3V pin but then disconnected before uploading)
GPIO2---NC
RST------NC

Ive uploaded code to ESP8266 before but it was a while back. I have the black ESP01 module i believe its called.
 

Thread Starter

quique123

Joined May 15, 2015
389
I just tried with an Arduino UNO which is what I originally used and I get pretty much the same error:

Code:
esptool.py v2.6
2.6
esptool.py v2.6
Serial port /dev/cu.usbmodemFD121
Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/upload.py", line 25, in <module>
    esptool.main(fakeargs)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 2653, in main
    esp.connect(args.before)
  File "/Users/quique123/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool/esptool.py", line 468, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
 

Thread Starter

quique123

Joined May 15, 2015
389
Ok i just tried the ftdi adapter and it uploaded fine. So:

Rx-Tx
Tx-Rx
3v3-EN & Vcc
GND-GPIO0 & GND

So Im just weirded out why the previous setups didnt work. I just took this FTDI adapter out of its sealed bag so I know I hadnt used it before. And in my notes I dont show having used a voltage divider before and I have 2 specific notes that show my wiring:

first with the nano, tx-rx and rx-tx and in the serial monitor i was able to write to it and get responses. That didnt work this time.

second with the UNO, rx-rx and tx-tx and i was able to upload the sketch for sampling dht22 and posting to cloud server for emoncms and to this day that ESP is still running fine.

I mean, my notes might be wrong or incomplete, but i dont know...ill check visual evidence such as pictures and videos to see if I did something different than my notes.
 

dendad

Joined Feb 20, 2016
3,257
I have found some ESP8266 boards to be fussy. And a couple of mine no longer work. There are some forum comments about the lack of power supply stability bricking some too.
But it just may be the phase of the moon or you not holding your mouth quite right ;)
 

Alibaba99

Joined Feb 1, 2020
3
If I connect an Esp8266 to a battery and dht sensor, how would I program the esp8266 to be configurable by a user to connect to a wifi?

Iow, when it is powered up by th user by plugging in a battery, how could he configure the module to connect to a local wifi?
Have a look at the Mipy_ESP project:



this framework handles all you need regarding wifi connection and remembers networks and passwords. Also sets up a basic webserver from the chip, so that you can log on the chip to wifi by entering settings in a webpage.

All tested and key ready :)

best regards

Mod: Deleted Link.
 
Top