※ Note: The ESP8266 has a 3.3V operating voltage. In this guide, 5V is applied to the RX and TX pins of the ESP8266, so the ESP8266 board may be broken. ※ Due to a bug in the
WiFiEsp
library, sensor data transmission is possible, but actuator commands can not be received at arduino side.
Arrangements: Arduino, Arduino AC power, ESP8266
Please apply AC power to Arduino.
1.1 Circuit configuration
Esp8266 | Arduino |
---|---|
Rx | Rx |
Tx | Tx |
CH_PD | 3.3V |
VCC | 3.3V |
GND | GND |
GPIO0 | GND |
Arduino | Arduino |
---|---|
RESET | GND |
1.2 ESP8266 Flash Tool, SDK Download
1.3 Flash ESP8266 Firmware
FLASH_TOOL_DIR/ESPFlashDownloadTool_V3.4.4.exe
Download Patch Config
window of Flash Tool as below.FileAddressSDK_DIR/bin/esp_init_data_default.bin0xfc000SDK_DIR/bin/boot_v1.6.bin0x00000SDK_DIR/bin/blank.bin0xfe000SDK_DIR/bin/at/1024+1024/user1.2048.new.5.bin0x01000
Start
at the bottom. – If downloading does not work, try setting BaudRate to 115200. – If it continues to fail, turn off both Arduino and Esp8266, wait 5 minutes and try again.
MAC address
shown at the bottom left of FlashTool. We will use it later when registering the gateway.
1.4 Verify flashing and Baudrate set
Both NL & CR
,
115200
BaudRate in the bottom-right of the serial monitor.
AT
command and check whether
OK
response is coming.
AT + GMR
command to check the firmware version. – Finally, to set the Baudrate of the ESP8266 to
9600
, transmit
AT + UART_DEF = 9600,8,1,0,0
.
AT commands
must be capitalized.
command | response | description |
---|---|---|
AT | OK | Verify normal operation of AT command |
AT+GMR |
AT version:1.3.0.0(Jul 14 2016 18:54:01)
SDK version:2.0.0(656edbf) compile time:Jul 19 2016 18:44:22 OK |
Check to firmware version |
AT+UART_DEF=9600,8,1,0,0 | OK | setting of Baudrate |
2.1 Circuit configuration
Esp8266 | Arduino |
---|---|
Rx | GPIO7 |
Tx | GPIO6 |
CH_PD | 3.3V |
VCC | 3.3V |
GND | GND |
2.2 Install libraries
WiFiEsp
Thingplus
ArduinoJson
PubSubClient
Time
Timer
Reference : Install arduino firmware
2.2.1 Modifying the PubSubClient’s Header File
Windows : My Documents\Arduino\libraries\
Mac : ~/Documents/Arduino/libraries/
Linux : /home/<your user name>/sketchbook/libraries
MQTT_MAX_PACKET_SIZE 196
MQTT_KEEPALIVE 120
2.2.2 config setting
mqtt.thingplus.net
->
mqtt.sandbox.thingplus.net
void ThingplusClass::begin(Client& client, byte mac[], const char *apikey) { const char *server = "mqtt.sandbox.thingplus.net"; const int port = 1883; this->mac = mac; snprintf(this->gatewayId, sizeof(this->gatewayId), PSTR("%02x%02x%02x%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); this->apikey = apikey; this->mqtt.setCallback(mqttSubscribeCallback); this->mqtt.setServer(server, port); this->mqtt.setClient(client); }
Reference : Register Gateway
LibrayPath/Thingplus/examples/ArduinoEsp8266/ArduinoEsp8266.ino
as it is an example of connecting the esp8266 to the Arduino board.