ESP8266 Wifi P2P with Arduino - arduino

I am fairly new to using the ESP8266 and trying to get two of them to connect directly via the wifi generated by the server. For now, I am using two Arduino Unos, one for each wifi module. I am sending the ESP8266 AT commands from the Serial Monitor. I have one ESP8266 dedicated to being a server and the other as a client. My goal is to send a simple message from the client to the server without connecting to any external wifi. Here is the series of AT commands I am using in the Arduino Serial Monitor.
Server code:
INPUT: AT+CWSAP="ESP SSID","ESP PASSWORD",2,3
OUTPUT: OK
INPUT: AT+CWMODE=3
OUTPUT: OK
INPUT: AT+CIPMUX=1
OUTPUT: OK
INPUT: AT+CIPSERVER=1,80
OUTPUT: no change
OK
INPUT: AT+CIFSR
OUTPUT: +CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"2e:3a:e8:20:f9:96"
+CIFSR:STAIP,"0.0.0.0"
+CIFSR:STAMAC,"2c:3a:e8:20:f9:96"
Client Code:
INPUT: AT+CWMODE=3
OUTPUT: OK
INPUT: AT+CJAP="ESP SSID","ESP PASSWORD"
OUTPUT: WIFI CONNECTED
WIFI GOT IP
INPUT: AT+CIPMUX=1
OUTPUT: OK
INPUT: AT+CIPSTART=2,"TCP","192.168.4.1",80
OUTPUT: ERROR
2,CLOSED
I cannot figure out why I am getting this error when trying to start a connection with the server. I am aware of the thread Communication between 2 ESP8266 WiFi modules without router using AT commands but none of these solutions have fixed this error.
I have also swapped the original ESP8266s with 2 new ones, which did not solve the problem. In addition, I have been able to communicate with these wifi modules using a smartphone with a TCP client app, so I don't think any of my hardware is broken. Thank you for any suggestions and help.

After some extreme trial and error, I got the connection to work. After manually setting the IP address of the client using
AT+CIPSTA="192.168.4.2"
the connection could be made using the AT commands above. I guess the client needs to contain the same first three parts of the IP address as the server. I'm not sure if I'm just a noob that should know about this IP address nomenclature, but here is an official answer to help others with the same problem. Good luck!

Related

ESP8266 connection to a Arduino Nano

I am trying to connect a WiFi module (ESP8266) to a "funduino" development board (Arduino Nano) but I have no success. Since I tried so much schematics I've found on the internet about the connection between them two, I kindly ask here if is anyone who succeed in "pairing" this two devices.
I am asking for the schematic and a functional source code.
Regards
The ESP-01 by default comes with nonOS SDK bootloader that communicated via AT commands, you can find the complete command set from Expressif here. This is designed for an MCU (like Arduino Nano) to use it purely as an WiFi module rather than using it as a stand-alone MCU (for which it will require NodeMCU SDK).
If you ever upload an Arduino sketch up to the ESP-01, it will erase the AT Command firmware.
Assuming your ESP-01 is still having the AT Command firmware. What #Ben provided is a sketch that allows you to type AT commands via the Serial Monitor to internact with the ESP-01, it is manual, and good for testing if ESP-01 is working (you type AT and press return on Serial Monitor, the ESP-01 will ack with Ok) but not practical as a real application. The minimum commands required to established an WiFi connection with ESP-01 is listed below.
AT+CIPMUX=1 - Enable single (0) or multiple connection (1) to the web server.
Multiple connection is a good option if you are repeatedly sending
out or reading data from the Internet.
AT+CWMODE=3 - Set WiFi mode: 1 is station mode (ESP8266 is client), 2 is AP mode
(ESP8266 acts like a WiFi router where your phone or PC can connect),
3 is AP+station mode (make the ESP8266 do both)
AT+CWJAP=“<your-ssid>”,”<your-pw>” - Connect to your WiFi. Provide your SSID name
and password inside the double qoutes.
AT+CIFSR - This returns the IP address of the module, indicating that it has
successfully connected to your WiFi router.
Once the WiFi connection is established, you can further communicate with the ESP-01 via the connection, like accessing a website for example:
AT+CIPSTART=0,"TCP", "www.example.com","80” - Start TCP or UDP connection. The
0 is the id of the connection.
AT+CIPSEND=0,16 - Command to tell the module data is ready to be sent. 0 is the
connection id, and 16 is the length of the data to be sent.
After this command, the ESP8266 will reply with the “>”
character to tell us that it will be waiting for the data to be
sent. If successful, the module will reply with “SEND OK”
GET / HTTP/1.1 - Send the http header, and other data, etc...
You can write your own sketch to automate those AT commands for interacting with with ESP-01 once you understand the AT commands required for establish a WiFi connection.
Here are two resources that I personally found extremely useful for doing more than connecting to WiFi.
STM32-ESP-01 Web Server - although this is for interfacing with STM32, the main difference is the pin assignment, so you should be able to port to Arduino easily.
MQTT via ESP-01
As for hardware interface, please noted that what #Ben provided is correct in principle, but you need to be aware that the ESP-01(ESP8266 to be precise) is a 3V3 MCU, so the connection is depended on what kind of host board you are using. If you are using Arduino Uno/Nano, both are having a 5V MCU, you will need a voltage divider (two resistors to drop the voltage to 3v3 before connecting to ESP-01) or a level shifter chip at least for the ESP-01 Rx pin to avoid the potential damage to the ESP-01.

Connect ESP8266 to open network using AT commands

We have an Arduino Uno connected to an ESP8266 and a bunch of other devices. We are using the ESP8266 as a WiFi connector (obviously) to send data to REST API.
Our problem is that we have to use an open network, and there is no AT-* command that does "connect to SSID without password".
We have considered using the CWJAP command, passing password as "", but have failed -- that may be because of a dumb AP we used (TPLINK), but we are wondering if this is the right approach (sending nothing vs nothing being sent dilemma).
Have you perhaps had any success with using such a configuration?
Proper way to connect to open network using AT commands is to provide:
AT+CWJAP=ssid,password
for example:
AT+CWJAP="Johns Network", ""
Which would be a string:
"AT+CWJAP=\"Johns Network\",\"\"".

Arduino & ESP8266 - strange characters in response

I'm working on an Arduino Uno + ESP8266 project.
I try to use them as a web server on Wi-Fi network to control a motor that connects to Arduino - basically a trigger system that receives signals via Wi-Fi. Currently, I've successfully connected ESP8266 to my access point by sending AT commands from Arduino. Another client on the same network can statically access ESP8266's assigned IP address.
However, when I try to catch some HTTP queries (I want to use them as conditions to control the motor) I occasionally encountered the non-ASCII characters in HTTP request. I use serial comm to debug, please look at the screenshot in the link below:
Arduino - Computer serial communication for debugging
The line ",519:POST ..." should contain a complete number following "/?", but there's some strange characters instead. So I cannot determine the input data to control motor. Once in a blue moon, the expected format of request shows up as follows:
The correct data received
There's no issue with the HTTP response part, even though I got the uninterpretable request, I can still send the JSON error message back to client.
Attempt Note:
The Arduino uses different serial ports to talk to computer and ESP8266. Since the connection can be established, and the data being sent, I believe that the baud rate is simply correct on both side. (115200 for ESP8266, 9600 for computer - also tried 115200 for both and got the same result)
I use V3.3 from Arduino as power source for ESP8266. But I also use voltage regulator to smooth out the current as many people suggest that. The problem still remains.
I'm struggled with this issue for a few days, just want to know if anybody had the similar experience, or could give some clue for the next step.
After a considerable effort to stabilize the circuit, I switched to NodeMCU and got the system working perfectly. I assume that ESP8266 alone is somehow not robust enough without other components, which I unfortunately have no knowledge on.
So I'd like to close this thread with a short recommendation for anybody struggling with the same issue to switch to NodeMCU (which would replace both Arduino and ESP8266); if that could support the requirement.

Arduino Yun WifiStatus Example Failing

I am able to connect and upload the WifiStatus example per the instructions on the Arduino Site/Examples/Yun. However, when I hit the serial monitor button it is supposed to print out the relevant Wifi stats, instead it says "unable to connect" and the final line goes a bit further..."unable to connect: is the sketch using the bridge". Any ideas? A post suggested reseting the 32U4, which I did, but no luck.
Incidently, all of this is over Wifi. Board and port are set per instructions. Yun pings fine and receives the uploaded sketch fine.
More code is usually more illuminating... so you might get better answers when you provide more information.
"is the sketch using the bridge" seems to indicate that there is some problem with the Bridge library. Is it being initialized? Did initialization (i.e., "Bridge.begin()" succeed?
A sketch with bridge functional and serial monitor via network connection cannot be running simultaneously as they use the same hardware connection.
You may use the serial monitor via USB port, or Serial TX/RX pins, or SoftwareSerial for this.

Why don't I receive signal and status for WiFi using QSystemNetworkInformation

I wrote a piece of software which does nothing else than reading network status and signal strength for each network mode (gsm, wlan (wifi), bluetooth, ...) on my device (Nokia E51) and printing it out.
My test device is connected to bluetooth, wlan (wifi) and 3G (wcdma), but it's only able to give me the signal strength of 3G (and also returns the correct name of my carrier). for wlan and bluetooth it gives me the undefined state und isn't able to read any signal strenght. But I am able to receive the IP address of the network I'm connected via wlan.
All I do is:
QSystemNetworkInformation::networkSignalStrength(QSystemNetworkInformation::WlanMode);
and calling the method for the network status.
As I said, it works flawless for 3G.
Any ideas? Thanks a lot.
After an SDK update, everything works fine without any code changes. So the problem wasn't in the coede, but in the QtMobility backend.

Resources