Hey,
first of all thanks for sharing such a project
second my question is if the android app and the module allow me to get data on any network or the android phone and the module must be connected to the same router.
Thanks in advance.
You can buy pin headers (usually they are rows of 20 or 40 pins and costs a few cents only) and cut them to fit your needs.
You'll need to solder 4 pins on each side of the ESP8266-02 module. To simplify your task, use a breadboard and plug the pins there at the right distance, to have them stay steady, then put the module on top, then solder.
Do I need female jumperwires to connect with arduino pro mini, or do the male jumperwires fit in the holes of a arduino pro mini? i'm a huge noob beginner in Arduino. I would appreciate a quick reply, i'm really in a rush
Te Pro Mini boards that I've bought were without pre-soldered headers. Therefore I had the option to chose if I use male headers (thus female Dupont cables) or female headers (thus male jumper wires). You need to look what kind of pin header has the Pro Mini board that you'll buy, or if it does not have like the one I have, then choose which one you like to use. From the electrical point of view, it does not matter really, excepting that the male headers are exposed, thus being easier to make a short-circuit by accident if you are not careful enough.
The 3.3V power supply from the electrical schematics is not bought but it is built from ready available electrical components.
The main power supply is 5V and it is recommended to be at least 1A (so more than 1A is ok too, but not required).
It is also relevant to not buy the cheapest 5V DC power bricks, since usually their regulation is not really good and then your ESP8266 module may act strange (e.g., resets itself, lose WiFi connection, etc). The LM317T IC used to get 3.3V from 5V is taking care of the regulation too, but sometimes even so, you can have issues with the ESP8266 (based on my experience with this module).
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.
Last Visit: 31-Dec-99 18:00 Last Update: 21-Sep-24 4:51