You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ESP8266 WiFi Module is a self-contained stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor. The ESP8266 module is an extremely cost-effective board with a huge, and ever-growing, community.
The code itself is straightforward and well commented (help is of course welcome) but I wanted to explain something I struggled with when I first was learning my way through the Arduino world, and that is the difference between `Software Serial` and `Hardware Serial`.
84
+
85
+
Let's go through the function called `sendDataToWiFi()`. This function allow the Arduino board (the logic board) to communicate with the ESP8266 board (The WiFi board)
86
+
87
+
```cpp
88
+
String sendDataToWiFi(String command, const int timeout, boolean debug)
89
+
```
90
+
91
+
So after connecting the two boards following the wiring diagram above, and initializing a new Software Serial object called `wifi`
92
+
```cpp
93
+
// ESP TX => Uno Pin 2
94
+
// ESP RX => Uno Pin 3
95
+
SoftwareSerial wifi(2, 3);
96
+
```
97
+
98
+
Anything passed to the `print()` function will be sent through the pin 2 to the WiFi board.
99
+
```cpp
100
+
wifi.print(command); // send the read character to the esp8266
101
+
```
102
+
103
+
Pin 3 is then used to read any response coming back from the WiFi board through the `read()` function.
104
+
```cpp
105
+
while((time+timeout) > millis()) {
106
+
while(wifi.available()) {
107
+
// The esp has data so display its output to the serial window
108
+
char c = wifi.read(); // read the next character.
109
+
response+=c;
110
+
}
111
+
}
112
+
113
+
return response;
114
+
}
115
+
```
116
+
117
+
Finally, for code that goes into the WiFi board (ESP8266 ESP01) and more explanation, please head out to this repo: https://github.com/MecaHumArduino/esp8266-01-aws-mqtt
0 commit comments