I am not sure exactly what you try to ask, but the if condition sends an AT command to the ESP8266 module and it waits a little for an answer. The answer can be ESP8266::Error::NONE, meaning that the sensor replied and all is OK or some specific error, such as timeout, wrong answer, etc.
In your case, most probably, the code from the else clause is executed because the ESP8266 module does not aswer to the AT command. You can debug this issue with the help of an USB-TTL module. Connect its RX pin to the TX pin of your ESP8266 module, and keep in mind that you need a common GND line. Use RealTerm, Putty or other software that knows to deal with the Serial/UART protocol.
:\WeatherStationComplete\arduino\WeatherStation\WeatherStation.ino: In function 'void loop()':
WeatherStation:205: error: 'ESP8266::Error' is not a class or namespace
if ( esp.ipd( ipdData) == ESP8266::Error::NONE) {
^
Using library ESP8266 in folder: C:\Program Files (x86)\Arduino\libraries\ESP8266 (legacy)
Using library DHT22 in folder: C:\Program Files (x86)\Arduino\libraries\DHT22 (legacy)
exit status 1
'ESP8266::Error' is not a class or namespace
I think you have a problem with the compiler. The ESP8266::Error is an enum class, and this is only available starting with C++11. Very likely you are using an older compiler version or your Arduino IDE does so. Try to download the latest Arduino IDE and try again.
Also please be sure that this code line:
C++
#include<ESP8266.h>
is available somewhere in the beginning og WeatherStation.ino file. Notice that in the archive seems to be a typo (a ";" at the end of that line, which should be deleted).
thank you for your reply.
I am using the latest version Arduino 1.6.10, WINDOWS 10 PC,
Library ESP8266 does not work on any sketch,
suspect its is the IDE and/or the WINDOWS 10 Software
any more suggestions?
I just compiled the WeatherStation.ino sketch, using Arduino IDE 1.16.10, the ESP8266 and DHTLib from the link provided in the article (downloaded just now). It compiles fine for Arduino/Genuino UNO, Arduino Nano and Arduino Pro Mini (which is what I actually used in the project). I use Windows 7 Pro x64.
It should be something local to your system/environment which prevents the compilation. If you want, I can upload the complete Arduino IDE I've used today to check the compilation (its a fresh download from today, and only added the ESP8266 and DHTLib libraries - no other changes or libraries) to web-engineering.info | High-quality resources for learning developers and makers[^], and you can download it from there if you like. Just let me know if you want me to do this upload for you.
// Arduino pin number used for the communication with DHT22 sensor.// A custom 1-Wire communication protocol is used for this module.// See: https://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf#define DHT22_PIN 9
//declaring mositure sensor pin to A1#define moisturePin A1
//declaring ldr pin to 13#define ldrPin 13
// pins number for WiFi enabled/disabled LEDs#define WIFI_DISABLED_LED_PIN 7
#define WIFI_ACTIVE_LED_PIN 8
// arduino pin used to connect to CH_PD (Power Down) WiFi module pin#define WIFI_CH_PD_PIN 2
// arduino pin used to connect to RESET WiFi module pin#define WIFI_RESET_PIN 3
// interval-time (in ms) to check WiFi module (5s)#define WIFI_CHECK_TIME 5000
// interval-time (in ms) to restart the WiFi ESP8266 module // in case that it become unresponsive (hardware reset required!)#define WIFI_RESTART_TIMEOUT 30000
#include <dht.h>
#include <ESP8266.h>;
#include <LiquidCrystal.h>
LiquidCrystal lcd (12,11,6,13,5,4);
// keep tracking the average temperature and humidity // values, starting with last system resetfloat avgTemperature = 0;
float avgHumidity = 0;
// used to compute the averate temperature value
unsigned long avgDhtStep = 1;
//keep the track of moisture levelfloat avgMoisture=0;
//keep light intensity trackedint intensity=0;
// data template for sensorsconstchar SENSORS_DATA_TEMPLATE[] PROGMEM =
"{\"temperature\": %s, \"avgTemperature\": %s, \"humidity\": %s, \"avgHumidity\": %s, \"voltage\": %s, \"freeRam\": %d, \"avgMoisture\":%s,\"intensity\":%d}";
// DHT22 sensor controller class
dht dht22;
// ESP8266 WiFi module controller
ESP8266 esp( Serial);
enumclass Command {
GET_ALL_SENSORS_DATA = 97
};
/**
* Check if ESP8266 (WiFi) module is active.
*/
boolean checkWiFi() {
lcd.begin(16,2);
lcd.print("WIFI CHECK ");
// try to communicate with ESP8266 moduleif( esp.at() == ESP8266::Error::NONE) {
lcd.print("WIFI ACTIVE");
digitalWrite( WIFI_DISABLED_LED_PIN, LOW);
digitalWrite( WIFI_ACTIVE_LED_PIN, HIGH);
returntrue;
} else {
lcd.println("INACTIVE");
digitalWrite( WIFI_ACTIVE_LED_PIN, LOW);
digitalWrite( WIFI_DISABLED_LED_PIN, HIGH);
returnfalse;
}
}
/**
* Prepare Wifi Communication:
* - prepare pins for the ESP8266 module
* - hardware reset ESP8266 module
*/void setupWiFi() {
lcd.print("WIFI SETUP");
// set pins used for WiFi status LEDs as OUTPUT
pinMode( WIFI_ACTIVE_LED_PIN, OUTPUT);
pinMode( WIFI_DISABLED_LED_PIN, OUTPUT);
// Arduino pin connected to ESP8266 CH_PD pin is set to OUTPUT.// To keep the module active, this pin must be kept HIGH.
pinMode( WIFI_CH_PD_PIN, OUTPUT);
digitalWrite( WIFI_CH_PD_PIN, HIGH);
// Arduino pin connected to ESP8266 RESET pin is set to OUTPUT.// To avoid random resents, we keep this HIGH.
pinMode( WIFI_RESET_PIN, OUTPUT);
digitalWrite( WIFI_RESET_PIN, HIGH);
// perform a hardware reset (ESP8266 RESET pin goes LOW)
digitalWrite( WIFI_RESET_PIN, LOW);
delay( 200);
// allow ESP8266 module to boot
digitalWrite( WIFI_RESET_PIN, HIGH);
// baud 115200, communication with ESP8266 module
Serial.begin( 115200);
// wait for the ESP8266 module to start, after the forced hardware reset.// We check the wifi state once a second, until the ESP8266 WiFi module responds.while( !checkWiFi()) {
delay( 1000);
};
// start UDP connection - wait on all ports
esp.atCipstartUdp();
}
/**
* Read the voltage which powes the system on the 5V line.
* This is possible by using the internal voltage reference
* available in some ATmega MCUs such as ATmega328p
*/float getVcc() {
long result;
// read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
// wait for Vref to settle
delay(2);
// convert
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
// Back-calculate AVcc in mV
result = 1103700L / result;
// return response in voltsreturn result / 1000.0;
}
/**
* Update the data (perform new reading) for
* the DHT22 temperature and humidity sensor.
* After calling this method, the temperature
* and humidity values are available by reading
* DHT.temperature and DHT.humidity.
*/void updateDHTData() {
if ( dht22.read22( DHT22_PIN) =='DHTLIB_OK') {
avgTemperature = ( avgTemperature * (avgDhtStep - 1) + dht22.temperature) / (float)avgDhtStep;
lcd.print("avgTem=");
lcd.print(avgTemperature);
avgHumidity = ( avgHumidity * (avgDhtStep - 1) + dht22.humidity) / (float)avgDhtStep;
lcd.print("avgHum=");
lcd.print(avgHumidity);
avgMoisture=analogRead(moisturePin);
lcd.print("avgMois=");
lcd.print(avgMoisture);
intensity=analogRead(ldrPin);
lcd.print("Light=");
lcd.print(intensity);
}
}
/**
* Get the data string using a pattern and the parameter values.
*/void createSensorsDataFromTemplate( char *&data) {
char buffTemp[7] = {0}, buffAvgTemp[7] = {0}, buffAvgHum[7] = {0},
buffHum[7] = {0}, buffMois[7] = {0},buffAvgMois[7] = {0},buffInten[5] = {0},buffVcc[5] = {0}, tmpl[140] = {0};
char *pTmpl = tmpl;
uint8_t templateLen = -1;
// read template from PROGMEM
getPMData( SENSORS_DATA_TEMPLATE, pTmpl, templateLen);
// create data string from template by replacing// parameters with their actual values from sensors
sprintf( data, pTmpl,
dtostrf( dht22.temperature, 6, 1, buffTemp),
dtostrf( avgTemperature, 6, 1, buffAvgTemp),
dtostrf( dht22.humidity, 6, 1, buffHum),
dtostrf( avgHumidity, 6, 1, buffAvgHum),
dtostrf( analogRead(moisturePin), 6, 1, buffMois),
dtostrf( avgMoisture, 6, 1, buffAvgMois),
dtostrf( analogRead(ldrPin), 4, 2, buffInten),
dtostrf( getVcc(), 4, 2, buffVcc),
getFreeMCUMemory());
}
/**
* Process requests (with or without parameters).
* The commands are defined as constants, and
* have the pattern: CMD_command_name.
* @param data
* the data to be processed (+IPD:
*/void processRequest( char *data) {
char progmemData[150] = {0};
char *pData = progmemData;
// first char represents the commandchar cmd = *(data);
switch ( (Command)cmd) {
case Command::GET_ALL_SENSORS_DATA:
createSensorsDataFromTemplate( pData);
esp.atCipsend( pData);
break;
default:
// nothing to do ...break;
}
}
/**
* Prepare ths system. This method is called when the system starts.
*/void setup() {
// setup WiFi - ESP8266 module
setupWiFi();
// Get initial data (temperature & humidity) from DHT22 sensor.// Add a 2 seconds delay to prevent timeouts from the sensor.
delay( 2000);
updateDHTData();
}
/**
* Loop method which executes again and again.
*/void loop() {
// Incomming real data via IPD is 1 byte (the command identifier byte).// The first bytes are: "+IPD,n:", followed by the real datachar data[10] = {0}, *ipdData = data;
// Incomming data from ESP8266 module// Lengt must be greater than 7 bytes ("+IPD,n:")if ( Serial.available() > 7) {
// process request received from UDP port: (wait 50ms for data)if ( esp.ipd( ipdData) == ESP8266::Error::NONE) {
// process the request
processRequest( ipdData);
}
}
// a small delay before checking againd for WiFi incomming data
delay( 25);
}
That is because the ESP8266 module does not reply to AT command, sent by Arduino. The AT command does nothing really, but is a simple way to check that the ESP8266 module is alive and is communicating via serial. Be sure that RX and TX lines are twiseted between Arduino and ESP8266 module.
Also, I recommend you to try out a Serial TTL module (costs about 2-3 EUR, and is helpful in a lot of DIY projects involving serial communication), connected to the RX/TX pins of the WiFi module, and using for example RealTerm (windows only) or Putty, check if your WiFi module works and receives commands.
Be sure that your CH_PD pin of the WiFi module is tied high, otherwise the WiFi module may be in a kind of "unclear" state, which may result in not being able to start, or randomly restarting by itself. In addition, it is relevant to be sure that you have the correct firmware written to your ESP8266 WiFi module, and first be sure that it works (check it with the Serial TTL module outside the complete circuit).
Check my WoT with Arduino for Beginners: Part 3 - Connecting to the Internet via WiFi[^] article about details on how to update the ESP8266 firmware and more information about this WiFi module.
In the version shown in this article, the WeatherStation WiFi module acts an WiFi AP (access point). Thus, you need to connect your Android device (smartphone, tablet, etc) to the network exposed by the weather station. In your Android device WiFi configuration panel, search for the WiFi network with SSID you provided for your WeatherStation then connect to it.
You can connect multiple Android devices at once to the weather station, but you can't connect one device to multiple stations, with the current implementation. This can be extended, so that one WeatherStation acts as a gateway, but this option is not presented in this article.
But sir how to provide SSID to WiFi module it creates 1 ESP_CF6ED2 but When i try to connect through app it doesn't recognise. Can you show a detailed step how to do that connection between app and wifi module.
Thanking you for previous replies,hope you will reply to this also soon.
Akash
Also, there is a atCwsap method (part of the ESP8266 library), allowing you to do this directly from the Arduino code, in case that you don't have a Serial TTL module.
The enable LED has nothing to do directly with AT+CWSAP. AT+CWSAP is only setting the SSID of your WiFI module and the WiFi access password. Also be sure that you have set the WiFi module in AP (this is more stable) or AP+STA mode, using the AT+CWMODE command, with the right parameters: CWMODE · espressif/ESP8266_AT Wiki · GitHub[^]
Not getting the enable LED on, has to do with the fact that Arduino and your ESP8266 module does not communicate (does not matter if SSID is right, or the Android device is connected, or if the rest of the things works). The enable LED lights up after the Arduino sends an AT command to the WiFi module and the WiFi module replies back with OK. So in your case, this (WiFi does not says 'OK') does not happens, for any reason.
As I already wrote in my other messages to you, there are various factors involved in this: hardware related issues, maybe wrong connections with RX/TX lines, wrong firmware in your ESP8266 module, and so on. In my first answer to you, I recommended you to try the ESP8266 module with a Serial TTL module, or with a basic Arduino sketch, to ensure that that you get connection and the two "speaks". Did you done this ? You can't do 'blind' debugging with such devices, it just does not works like that...
The entire project presented in this article, was physically implemented and works, is not just a theoretical project, so it must by a issue with your particular configuration.
means that you'll see an WiFi network with SSID (name) "WeatherStation" and you can connect to it with your Android device (or other device), by using the password: "LetsNurture". The value 5 means that it uses WiFi channel 5 (in Europe there are 13 channels available) and 3 means that the WiFi uses WPA2 Pre-Shared-Key authentication.
So it looks that your WiFi module works. If the enable LED does not comes out, this means you have a problem with the connection between the Arduino board and the WiFi board, or some issues in your Arduino code. Remember, the RX pin of the Arduino board goes in the TX of WiFi module and the TX of the Arduino board connects to the RX pin of the WiFi module. These two connections must be made via a 3.3v Voltage Level Snifter module (there are other ways too, but that is the simplest for a beginner). Also notice that some Voltage Level Shifter modules are different than the ones in my diagrams (even if they look physically the same!), so you have to check the datasheet of your specific one.
If you don't see the WiFi AP after connecting the WiFi module to the Arduino, very likely means that it is a hardware issue with your device.
Check your connections, because you can easily burn up the WiFi module. Also use the TTL Serial Module on the same RX/TX lines, so you can see what (and if) the WiFi module says after connecting to Arduino. It may just enter a reset cycle, that'S why you can't see the AP afterwards.
Check of you are using the DHT22 sensor or the DHT11 sensor. DHT11 has a blue plastic case, and they need different code than DHT22. DHT22 has a white plastic case.
But if one is using a clone ATMEGA328P similar to the one in your diagrams, how is this actually achieved. What did you plug the board into to give you a usb connection to the IDE?
Seems something is missing from the parts list.
Thanks
Last Visit: 31-Dec-99 18:00 Last Update: 14-Jun-24 4:13