How to change WIFI credentials at runtime in ESP32? - arduino

I'm a little bit new to ESP32 and Arduino ID. I've been working on a project in which I want to switch the wifi network from one to another at any given time. But whenever I'm trying to close the existing connection (network) and reconnect to the new one, ESP32 crashes and gets rebooted. A bit peculiar behaviour I would say. Additionally, I even tried to use the EEPROM for the storage purpose, so, even when my ESP32 gets rebooted, it will take the updated values from the storage. Unfortunately, sometimes ESP32 crashes even when I update the variable which was being passed earlier to WiFi.begin(). Lastly, In my application, I'll be providing the new SSID and Password through the serial (COM) port. Can anyone help in achieving this task?

I tried a similar task with persisting values in memory. The ESP32 lacks an eeprom so you need to use some nvs (non volatile storage) functions as they are called for ESP32. See https://github.com/rpolitex/ArduinoNvs for example.

Related

HM-10 pairing with another HM-10 without knowing the MAC addess

I'm trying to figure out, how to connect two hm-10 module, when I do not know the slave MAC address. Imagine you have an electric longboard and lost you remote. You got yourself a new one and now want to pair with the board.
In the data sheet I cannot find any useful functions, to make this process easy.
I thought about making an unique name of the slave device and by making a pairing button on the master device. The pairing button would set the master device in the pairing mode (AT-ROLE1, AT+IMME1 in order to execute AT+DISC?). The results of the AT+DISC? command would be saved to an array and after finding the unique name of slave device, the index of the device/MAC address would be saved and used as a parameter for establishing the connection.
I'm using the firmware version v707.
The problem is, I do not find this solution as elegant and I think there must be a better way to do that, but I cannot find any information about it. Did anyone tried to do that and maybe has some insight? I'd very much appreciate it.
Only way I can think of on the HM10 is setting a unique name and scanning for that name.
Another way I have seen is some devices allow you to see service UUIDs in the advertising information so you can connect to the device that has the desired service UUID. But this doesn't seem possible on the HM10

Arduino OTA Firmware Backup ESP32

It is widely known that you can update firmware over-the-air using <Update.h> functionality: receive blob size over the network, call Update.begin(blob_size), consecutively call Update.write() until its done, then call Update.end(), and restart the board.
But is there a way to do a backup of current firmware binary using WiFi?
The short answer is "no", there's no support for dumping the firmware over WiFi.
I've not looked at how WiFi Update is implemented so I'm not saying it can't be done at all - just that you're going to have to implement it yourself. Just like Update, if the sketch doesn't already support it, it is likely not possible at all (so you can't backup from an ESP32 flashed with just any old sketch).

Problems connecting to nodemcu via johnny-five

I'm really having trouble connecting to my ESP8266. I was working with this setup for long time now and I didn't have to flash my boards. Now after having to use a different wifi i needed to flash the board. After doing the following
Updating to the newest ConfigurableFirmata
Using FirmataBuilder to download fitting firmata
Uploading the Firmata to the ESP8266
I can't connect via Johnny-Five anymore (getting the usual timeout error). I couldn't narrow down what it exaclty is (and I have been trying all day) but these are things that I have noticed (Using ConfigurableFirmata directly as well as using firmatabuilder and StandardWifiFirmata, all with the same behaviour)
an open Hotspot gets created even though I'm in Client Mode
when scanning for ports I do find the Module connected to my Wifi (Serial Monitor in Debug tells me the same too) but no open port is found, even though it's specified in the firmata.
I just can't narrow down the reason. I hope you guys can.
OK,
this was a simple user mistake. But since I lost a whole day searching for the error and I think others might too, I'll share my mistake here.
As I pointed out I created the Firmata as Client (thinking its a client to my Hotspot). But you will have to create it as a server (as you want to connect to the board)
It's as simple as that. If you are on http://firmatabuilder.com/ make sure you choose TCP Server if you want to connect to your board.

specifying connection on ESP8266 with AP and STA modes

I want to try to set up an ESP8266 (using the Arduino IDE) to occasionally connect to a wifi SSID to send telemetry back. I also would really like to be able to have it running a softAP for configuration/settings purposes. (i.e. so if you want to change internal settings in your code, you can connect directly to the device to access a web form to do so)
The problem is, I am not 100% sure how I know which is which when making an outgoing telemetry json query. I want it to go out on the STATION mode connection. Presumably in most cases the AP mode won't be connected, but there may be rare instances where both are connected at the same time. Thus how do I tell the device to specifically use the STA side of things when it needs to send data back over the internet?
I can't even seem to find any specific examples to ask if one or the other is connected. (you can poll WiFi.status() but - which one is it reporting?)
Any help is appreciated

ESP8266 Point to Point communication with 2 arduinos

I am using 2 esp8266 wireless modules to establish bidirectional wireless communication between 2 arduino boards (one mega and one uno) without the use of any earth based technologies (i.e. radio frequencies, wifi which relies on earth sattelites, etc.). My solution was to use the esp8266 to establish a private area network with both esp's acting as a station and an access point (AT+CIPMODE=3). Unfortunately, this solution has proven to be more of a hassle than it was worth.
To start, I have the esp's each wired according to this diagram
When I first started out, the red LED was on and the blue LED was off. During this time, I was able to send AT commands, establish the server, and achieve the communication I required by entering commands directly to the serial monitor. After this, I started writing a library using the SoftwareSerial library to allow me to issue commands directly through the program to set up the esp as needed upon start up of my script. Before doing this, I changed the baudrate to make sure it was running at 9600, and entered the AT commands in the serial monitor to make sure everything was working properly and it still worked.
After I began writing the library, before uploading the code with a test of the library I noticed the blue LED was lit solid now. Noticing this, I reuploaded the barebones script (I haven't uploaded the library code to the arduino yet) and the esp was no longer receiving the AT commands.
Does this indicate an issue with the board which I can fix or does this mean the board is done?
With my deadlines approaching fast in about 3 weeks it is crucial I get this wireless communication working so if this is an issue with the board, I'm going to have to scrap the esp's and use a different way of communicating. So my second question is, if this is the case, what are other viable options for establishing this communication? I have used xbee's before and while that would be ideal, they fall out of the budget I have been alotted so I need to keep it under $50 for this. If bidirectional communication is not possible for that price I can live with one way because I just need to get this system working. Basically I just need to transmit a single byte of data.
I realize this response is a little belated, and I hope you got it sorted: I've started working with the ESP8266 myself in the last few weeks, and hence why I was looking around for tutorials on direct communication between 2 units, when I found your post.
From what I've been able to ascertain, the AT commands are a part of the 'firmware' which ships with some modules. The Arduino code however starts loading onto the chips at memory address 0x0000, which is the same address that the firmware update tools use.
In other words, I believe that with the Arduino-coded program running on there, you lose the AT command functionality.
If you find a firmware update tool for the ESP8266 (plenty online) you'll get back the AT commands.
I suppose though the real question is why would you want to? It seems that the AT commands are just a way to treat the ESP as a dumb WiFi antenna. With the Arduino code, you're actually treating it as a micro-controller in its own right.

Resources