• Localization

ESP8266 "deep_sleep"

 

ESP8266

Kažkada buvau aprašęs  duomenų siuntimą ( temperatūros ) į Emoncms. Naudojau siųstuvą iš atmega procesoriaus ir Ds18B20 temperatūros jutiklio (maitinimas 3 vnt. AA 1.5 V) , duomenys perdavinėjau radijo ryšiu. Šiaip viskas ten buvo tvarkoje, po metų baterijos nežymiai išsikrovė, bet… viską kontroliavo Arduino ir GSM plokštė. p.s. GSM ir Arduino reikia pastovaus maitinimo (gana galingo) ir abonento.

Turėjau nusipirkęs kelis ESP8266 modulius, buvau pasidaręs ir plokštes moduliams prilituoti. Maitinime buvo ASM1117 stabilizatorius kuris nemažai srovės srėbė ramybės būsenoje (dar negalvojau apie maitinimą nuo baterijos). Taigi, tikslas buvo sukonstruoti bevielį WiFi temperatūros jutiklį maitinamą nuo baterijos (WiFi veikia visame name).

Perdarant plokštę teko išmesti ASM1117 3.3 V stabilizatorių, vietoj jo įdėjau MCP1826S-3002ED 3.0 V stabilizatorių (teko perdaryti plokštę, kojelių pajungimas skyrėsi), be elektrolitinių filtravimo kondensatorių . Nedėjau kondensatorių todėl, kad su jais srovės suvartojimas “deep_sleep” režime apie 3 mA. Nurakiau LED nuo ESP8266 modulio (gal be reikalo), Reset pin`ą sujungiau su GPIO16 (kitaip neveiks “sleep” režimas) ir vualia, srovės sunaudojimas ramybės būsenoje 0,13 mA. Žemiau esančiame filmuke matosi srovės šuolis iki 128 mA, bet siunčiant duomenis naudojama apie 80-70 mA.

deep_sleep

Duomenų siuntimas

Žemiau galite stebėti baterijos įtampos grafiką  realiu laiku, galima stebėti įtampos pokytį per dieną, per savaitę, per mėnesį, per metus (modulis išmatuoja įtampą).

Baterija 3.6 V 18650 tipo. Viską sumontavau ant maketinės plokštės (siųstuvas yra užmestas už knygų). Plokštės bylų moduliui prilituoti neduosiu, nes seno tipo neišsaugojau, o naujos dar nespėjau sutvarkyti.

ESP8622

Čia filmukas.

#include
#include
#include
 

const int sleepTimeS = 300; // Budėjimo laikas sekundėmis (dabar 5 min) -- sleep time in seconds (now 5 min)

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;
char pressure_char[6]; // buferis -- buffer
char pressure_temp_char[6];
char batt_char[6];

double T,P,p0,a;

const char* ssid = "**********"; //Tinklo pavadinimas -- WiFi name
const char* password = "***********";//Tinklo slaptažodis -- WiFi password
const char* apiKey ="***************"; //EmonCMS API raktas, įrašymui
const char* host = "giedriausweb.lt"; //Serverio adresas

#define ALTITUDE 11.41 //Gyvenamos vietos altitudė --- Altitude of living place
#define D5 14
#define D6 12
/*
extern "C" {
#include "user_interface.h" // to use deep sleep
uint16 readvdd33(void);
}
*/
ADC_MODE(ADC_VCC);

void slegis(){
char status;

// Loop here getting pressure readings every 10 seconds.
// If you want sea-level-compensated pressure, as used in weather reports,
// you will need to know the altitude at which your measurements are taken.
// We're using a constant called ALTITUDE in this sketch:

Serial.println();
Serial.print("provided altitude: ");
Serial.print(ALTITUDE,0);
Serial.print(" meters, ");
Serial.print(ALTITUDE*3.28084,0);
Serial.println(" feet");

// If you want to measure altitude, and not pressure, you will instead need
// to provide a known baseline pressure. This is shown at the end of the sketch.

// You must first get a temperature measurement to perform a pressure reading.

// Start a temperature measurement:
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.

status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.

status = pressure.getTemperature(T);
if (status != 0)
{
// Print out the measurement:
Serial.print("temperature: ");
Serial.print(T,2);
Serial.print(" deg C, ");
Serial.print((9.0/5.0)*T+32.0,2);
Serial.println(" deg F");

// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.

status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.

status = pressure.getPressure(P,T);
if (status != 0)
{
// Print out the measurement:
Serial.print("absolute pressure: ");
Serial.print(P,2);
Serial.print(" mb, ");
Serial.print(P*0.0295333727,2);
Serial.println(" inHg");

// The pressure sensor returns abolute pressure, which varies with altitude.
// To remove the effects of altitude, use the sealevel function and your current altitude.
// This number is commonly used in weather reports.
// Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
// Result: p0 = sea-level compensated pressure in mb

p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
Serial.print("relative (sea-level) pressure: ");
Serial.print(p0,2);
Serial.print(" mb, ");
Serial.print(p0*0.0295333727,2);
Serial.println(" inHg");

// On the other hand, if you want to determine your altitude from the pressure reading,
// use the altitude function along with a baseline pressure (sea-level or other).
// Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
// Result: a = altitude in m.

a = pressure.altitude(P,p0);
Serial.print("computed altitude: ");
Serial.print(a,0);
Serial.print(" meters, ");
Serial.print(a*3.28084,0);
Serial.println(" feet");
}
else Serial.println("error retrieving pressure measurementn");
}
else Serial.println("error starting pressure measurementn");
}
else Serial.println("error retrieving temperature measurementn");
}
else Serial.println("error starting temperature measurementn");

delay(500); // Pause for 5 seconds.
}

void setup()
{
Serial.begin(115200);
Serial.println("REBOOT");
pinMode(4,OUTPUT);
digitalWrite(4,HIGH); // BMP180 maitinimas --- BMP180 power
Wire.begin(12,14); //I2c magistralė SDA, SCL D5,D6
delay(100);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// Initialize the sensor (it is important to get calibration values stored on the device).

if (pressure.begin())
Serial.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.

Serial.println("BMP180 init failnn");
while(1); // Pause forever.
}
}

void loop()
{

digitalWrite(4, HIGH); //BMP180 maitinimas on --- BMP180 VCC on
delay(500);
slegis();
float vdd = ESP.getVcc() / 797.0;

Serial.print("Battery= ");
Serial.println(vdd);
float pressure_f = p0;
float pressure_temp_f = T;

dtostrf(pressure_f, 2, 2, pressured); //konvertuojam į Char tipo duomenis --- convert to Char type data
dtostrf(pressure_temp_f, 2, 2, pressuret);
dtostrf(vdd,2,2, battc);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}

//Formuojma URL nuoroda --- We now create a URI for the request
String url = "/cms/input/post.json?node=1&json={";
Serial.print("Requesting URL: ");
Serial.println(url);

// Siunčiama serverio užklausa --- This will send the request to the server
client.print(String("GET ") + url + "slegis:"+ pressured +",slegist:"+ pressuret+",baterija:"+ battc +"}&apikey=" + apiKey + " HTTP/1.1rn" +
"Host: " + host + "rn" +
"Connection: closernrn");

digitalWrite(4,LOW);
Serial.println();
Serial.println("closing connection");
Serial.println("ESP8266 in sleep mode")
ESP.deepSleep(sleepTimeS * 1000000,WAKE_RF_DEFAULT);
//Matuota su ASM1117 stabilizatoriumi --- Measured when module has ASM1117
//WAKE_NO_RFCAL 2.8 mA
//WAKE_RF_DEFAULT 2.8 mA
//WAKE_RFCAL 3.6 mA
//WAKE_RF_DISABLED 17.4 mA

}
Tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *