I have this Sketch to try the ESP8266 board with an Arduino UNO. I supplied external power to the UNO to prevent lack of juice. I get the following output on the Monitor serial window (showing reset and garbage characters). Don´t know what is happening here, might it be a problem with the SoftwareSerial library? Otherwise doing what I was expecting!!!! Any advice or insight most appreciated.
AT+RST
Module dosn't respond.
Please reset.
Init - ESP8266 Demo
AT+RST
WiFi - Module is ready
AT+CWMODE=1
AT+CWJAP="{MySSID}","{MySSID password}"
Connected to WiFi...
Temp: 24.89 C Presion: 970.86 Humedad: 84%
--------------------------------1
-KR+‹�- ESP8266 Demo
AT+RST
WiFi - Module is ready
AT+CWMODE=1
AT+CWJAP="{MySSID}","{MySSID password}"
Connected to WiFi...
Temp: 24.89 C Presion: 970.86 Humedad: 84%
--------------------------------1
--Init - ESP8266 Demo
AT+RST
Module dosn't respond.
Please reset.
// Example adapted from
// http://zeflo.com/2014/esp8266-weather-display/
// in turn reworked from:
// http://www.seeedstudio.com/wiki/WiFi_Serial_Transceiver_Module
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
#include <SoftwareSerial.h>
//#include <JsonParser.h> couldn't find this one!!!! use ArduinoJson instead
#define SSID "{MySSID}"
#define PASS "{MySSID password}"
// obtiene datos del clima
// localidad id: Coatepec=3530531, Xalapa=3526617
#define LOCATIONID "3530531"
//"188.226.224.148" //api.openweathermap.org
#define DST_IP "78.46.48.103"
SoftwareSerial dbgSerial(2,3);
// Función para conectar a WiFi con la tarjeta ESP8266
boolean connectWiFi()
{
Serial.println("AT+CWMODE=1");
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
dbgSerial.println(cmd);
Serial.println(cmd);
delay(2000);
if(dbgSerial.find("OK")){
dbgSerial.println("OK, Connected to WiFi.");
return true;
}else{
dbgSerial.println("Can not connect to the WiFi.");
return false;
}
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
dbgSerial.setTimeout(5000);
dbgSerial.begin(9600); // for debuging
Serial.println("Init - ESP8266 Demo");
// Prueba que el módulo esté funcionando
Serial.println("AT+RST");
// reset and test if module is redy
dbgSerial.println("AT+RST");
delay(1000);
if(dbgSerial.find("ready")) {
Serial.println("WiFi - Module is ready");
}else{
Serial.println("Module dosn't respond.");
Serial.println("Please reset.");
while(1);
}
delay(1000);
// Intenta conectar el módulo al wifi
boolean connected=false;
for(int i=0;i<5;i++){
if(connectWiFi()){
connected = true;
Serial.println("Connected to WiFi...");
break;
}
}
if (!connected){
Serial.println("Coudn't connect to WiFi.");
while(1);
}
delay(5000);
dbgSerial.println("AT+CIPMUX=0"); // set to single connection mode
}
void loop()
{
// Conceta con la pagina del servicio del estado del tiempo
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80";
// Envía el comando y espera por una respuesta, si hay algún error reintenta!
dbgSerial.println(cmd);
if(dbgSerial.find("Error")) return;
cmd = "GET /data/2.5/weather?id=";
cmd += LOCATIONID;
cmd += " HTTP/1.0\r\nHost: api.openweathermap.org\r\n\r\n";
// wait for prompt then send data
dbgSerial.print("AT+CIPSEND=");
dbgSerial.println(cmd.length());
if(!dbgSerial.find(">"))
{
dbgSerial.println("AT+CIPCLOSE");
Serial.println("connection timeout");
delay(1000);
return;
}
dbgSerial.print(cmd);
// Recorre el puerto serial hasta encontrar el segmento "main":{
while (!dbgSerial.find("\"main\":{")){}
// Lee el bloque hasta encontrar el corchete de cierre: "}"
unsigned int i = 0; //timeout counter
int n = 1; // char counter
char json[100]="{";
while (i<60000)
{
if(dbgSerial.available())
{
char c = dbgSerial.read();
json[n]=c;
if(c=='}') break;
n++;
i=0;
}
i++;
}
//
// Step 1: Reserve memory space
//
StaticJsonBuffer<200> jsonBuffer;
//
// Step 2: Deserialize the JSON string
//
JsonObject& root = jsonBuffer.parseObject(json);
if (!root.success())
{
Serial.println("parseObject() failed");
return;
}
//
// Step 3: Retrieve the values
//
double temp = root["temp"];
double presion = root["pressure"];
byte humedad = root["humidity"];
temp -= 273.15; // from kelvin to degree celsius
// Muestra los resultados de la consulta web
Serial.print ("Temp: ");
Serial.print (temp);
Serial.print (" C ");
Serial.print (" Presion: ");
Serial.print (presion);
Serial.print (" Humedad: ");
Serial.print (humedad);
Serial.println ("%");
Serial.println ("--------------------------------1");
delay(1000);
Serial.println ("--------------------------------2");
}