Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Arduino+ESP8266 transparent transfer to achieve POST access

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use Arduino+ESP8266 transparent transmission to achieve POST access", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "how to use Arduino+ESP8266 transparent transmission to achieve POST access"!

Abstract: the large and small pits encountered by ESP8266 in the process of accessing the network through transmission and the solutions are recorded and explained, and Arduino is used as the main control board to access the OneNET platform by POST.

Hardware:

Alientek ATK-ESP8266 module with UART-WiFi, official firmware with AT instruction, baud rate default of 115200 (8-bit data bit, 1-bit stop bit, no check)

Arduino UNO

PC machine

USB to TTL module

Some DuPont lines

Software:

Serial port software: xcomV2.0 or USR-TCP232-Test, the former can save multiple AT commands without network function, while the latter can only send a single AT command but has network function.

ArduinoIDEv1.8.0

First, use USB to TTL module to connect ATK-ESP8266 and PC for debugging (optional)

This step can use the serial port tool to issue AT instructions to manually configure the ESP8266, or debug to verify that the module function is normal.

The ATK-ESP8266 module is like this, with 6 pins, using 4 of them: VCC (3.3V~5V), GND,TXD,RXD

The connection mode is as follows, note: the ESP8266 modules of other manufacturers may connect to 3.3V of USB-TTL to be normal, otherwise there will be garbled or other abnormal errors, this power supply problem is worth paying attention to.

USB-TTLESP82665VVCCGNDGNDRXTX

TX

RX

Then insert USB-TTL into PC USB, and some PCs (mainly below win10) need to install CH340 driver to identify the serial port tool.

Next, open the serial port tool, here is xcom, as shown in the following figure.

Note a few points:

Serial port selection, need to correspond to the correct serial port

The baud rate defaults to 115200, and the rest is shown in the red box.

Check to send new lines

When you send an instruction, you don't need to hit enter to wrap the line, just click send (if you meet 3)

Because the PC communicates with the ESP8266 through the serial port, and the ESP8266 is connected to the AP, it doesn't matter whether the PC is connected or not (ESP8266 is used as an AP, except for the mode in which the PC connects to the AP).

If you send the simplest AT instruction, you will not get a reply (the correct answer is OK, exception such as garbled code or no response, etc.), the main reasons may be

RX,TX connected incorrectly, for example, ESP8266's RX connected to USB-TTL 's RX.

It is not a pure English character AT, or the serial port tool is not set according to the key points of the red box in the picture above.

Baud rate error. Verify the default baud rate of the ESP8266 module (the default baud rate of the ATK-ESP8266 module purchased here is 115200)

Voltage problem, this problem is more hidden and difficult to find, due to different manufacturers' production reasons, even if they all take ESP8266 as the core component, the power supply pin voltage requirements exposed are different. Also, the USB-TTL module you use may also be a cheat, and if the quality is not up to standard and the voltage is unstable, you will not be able to get the correct response. How to investigate? In fact, this is a big hole I ran into. I can only tell you how I found it. The ATK-ESP8266 module I use supports both 3.3v and 5V power supply. I find that the serial connection can only be found by the PC at 5v, but not at 3.3v at all. Later, I found the technical support of punctual Atom and said that their module could also connect to the serial port under 3.3v power supply. I immediately understood that it was my USB-TTL problem.

Firmware problem, if so, congratulations on winning the lottery, either give up the module or redo it according to the tutorial. But the key to rebrushing can solve the problem is to confirm that it is the firmware problem, otherwise it will be brushed for nothing. As for how to confirm, you still need some experience and professional tools. If you can't handle it, find a way to ask for help.

2. Arduino+ESP8266 transparent transmission (no USB-TTL)

Use the soft serial port of Arduino to connect to ESP8266. With regard to the soft serial port, this buddy wrote very clearly in the link below.

"Software simulates serial communication-- the use of SoftwareSerial library"

Https://www.arduino.cn/thread-47262-1-1.html

The connection method is as follows, similar to the USB-TTL connection mode, you should also note that the ESP8266 modules of other manufacturers may be connected to 3.3V to be normal, otherwise there will be garbled or other abnormal errors.

Arduino UNOESP82665VVCCGNDGNDRXTX

TX

RX

The C code is as follows, downloaded to the main control board with ArduinoIDE, this code indicates that the main control board interacts with ESP8266 through transmission, and the configuration needs to manually send AT instructions to the ESP8266 module through the serial port tool. Therefore, after downloading the code, do not open the serial port monitoring of Arduino, but use the serial port tool to issue commands to the main control board. Note: here Arduino hardware serial port baud rate is 9600, soft serial port Arduino-ESP8266 is 115200 (board default value).

# include SoftwareSerial mySerial (10,11); / / RX, TXvoid setup () {/ / put your setup code here, to run once: Serial.begin (9600); while (! Serial) {; / / wait for serial port to connect. Needed for native USB port only} Serial.println ("hardware serial!"); mySerial.begin (115200); mySerial.println ("software serial!");} void loop () {/ / put your main code here, to run repeatedly: if (mySerial.available ()) {Serial.write (mySerial.read ());} if (Serial.available ()) {mySerial.write (Serial.read ());}}

After the program download is complete, open the serial port tool xcom, the software settings are the same as the previous section, but the baud rate is 9600 (can also be other values, consistent with the download program).

As long as xcom returns OK for the issued AT instruction, everything is fine. There may be garbled codes when other instructions are first powered on, but this problem is ignored because the initial baud rate of ESP8266 firmware is 74880, which is inconsistent with the serial port tool settings.

If there is garbled or no response, continue to refer back to the reasons summarized in the previous section.

Then you can use the AT instruction to configure ESP8266. Examples of common instructions are as follows. Complete self-search information is easy to find.

AT

AT+RST, restart

AT+GMR, check the version number

AT+CWMODE=3, set to AP+STA mode

AT+CWJAP= "wifi name", "password", connection WiFi

AT+CIFSR, view the acquired IP

3. Arduino+ESP8266 transparently transmits POST data to OneNET

The operation of the OneNET section is not the focus of this article and will not be explained here.

The key code of the POST part is as follows, in which your_device_id and your_api_key need to be replaced with their own, and type=3 is essential, which represents the data format of datapoint.

Void post () {mySerial.println ("AT+CIPSEND"); delay (3000); echo (); mySerial.println ("POST / devices/your_device_id/datapoints?type=3 HTTP/1.1"); mySerial.println ("Host: api.heclouds.com"); mySerial.println ("api-key: your_api_key"); mySerial.println ("Content-Length: 20"); mySerial.println (""); mySerial.println ("{\" http\ ": 15}") / / value of datapoints delay (3000); echo (); mySerial.println ("+ +"); delay (3000); echo (); Serial.println ("over");}

After downloading the program, HTTP 200OK can be observed through the serial port tool, which indicates that POST is successful. A few 400ERROR may occur in the process, which is estimated to be caused by the incomplete execution of some commands in the module. When HTTP 200OK appears, you can go to OneNET to observe the data flow. As shown in the figure below, the data has been successfully uploaded to the cloud.

At this point, I believe you have a deeper understanding of "how to use Arduino+ESP8266 transparent transmission to achieve POST access". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report