Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By kas
#60590 Hi,

This is my data logger

Image

Every 30', device wakes up and send:
- Dallas 1-wire 18B20 temperature (connector, right side)
- BMP180 temperature
- BMP180 pressure
- battery voltage
- router connection time
- total ON time
ESP8266 will then go deep-sleep for the next 30 minutes

The 3.3V LiFePO4 battery supplies direct power to the mcu, w/o any DC/DC converter loss
Battery lifetime is 3 weeks, my ultimate goal is 3 months

Total process (wake up, data acquisition, router connection, ThingSpeak connection, deep-sleep) is currently 6/7 seconds.
I plan to bring it below 2 seconds, will keep you posted ;)
More details on request
User avatar
By al1fch
#60612 Hi !

I work on same things : ESP03, ESP12 or Wemos D1 Mini sending datas (temperature from DS18B20, voltage and session lengh) to ThingSpeak each hour.
Just like you direct power comes from a 1500 mAh 3,2V LiFepo4 battery.

I reach 6 months logging with ESP03 (no led) variant.
-full session are now under 2s (average = 1,77s) for a Wemos D1 Mini device 10m far from router a wall between them
-full session are now about 1s (average = 1,19s) for a, ESP12 device 3m from router and no wall between them.

To reach that I combine several tricks :
1) DS18B20 is a slow device so I reduce resolution to 10bits (faster acquisition)
Code: Select allDS18B20.setResolution(10);

2)I reduce Tx radio power :
Code: Select allWiFi.setOutputPower(16.0); //  16 dBm , max 20.5 dBm

3)I set fixed IP and DNS 'hardcoded' :
Code: Select allWiFi.config(IPAddress(192, 168, 1, 100), IPAddress(192, 168, 1, 254), IPAddress(255, 255, 255, 0), IPAddress(192, 168, 1, 254));

4) No ThingSpeak library used (to slow), just some simple HTTP GET request

5) 'timeout' added in router and server connection loops : if connection doesn't occur within 8s : 'go to sleep and try later'

6) When battery is low (3,1V to 3.0V ) internal resistance grows and produce brownout voltage during strong Tx radio current pulses.
470µF or 1000µF (selected for low leakage current and low ESR) help power and give some more weeks
You do not have the required permissions to view the files attached to this post.
User avatar
By kas
#60648 Thanks al1fch for all the tips, I was not aware that the Tx radio power was adjustable

Using static IP I am now able to get a consistent 165ms for router connection, and I adjusted timeout connection @2s (I switch off my router at night)

Image

1) DS18B20 is a slow device so I reduce resolution to 10bits (faster acquisition)Code: Select allDS18B20.setResolution(10);
I like the 12bit resolution better ;)

3) I set fixed IP and DNS 'hardcoded'
WiFi.config(IPAddress(192, 168, 1, 100), IPAddress(192, 168, 1, 254), IPAddress(255, 255, 255, 0), IPAddress(192, 168, 1, 254));
Did you try
Code: Select allWiFi.config(IPAddress(192, 168, 1, 100), IPAddress(192, 168, 1, 254), IPAddress(255, 255, 255, 0));
with no DNS ??

4) No ThingSpeak library used (to slow), just some simple HTTP GET request
This is my ThingSpeak connection function, any comments ??
Code: Select allboolean updateThingSpeak(String tsData)  {       //Thingspeak Stuff
  if (client.connect(eTSpeak.c_str(), 80))  {          // Make a TCP connection to remote host
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: "+eTSpeak+"\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: "+eApiKey+"\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData);
    client.stop();
    return true;
  }  else  {
    client.stop();
    return false;
  }
}


So my goal is to bring the full session time (wake up, data acquisition, router connection, ThingSpeak connection, deep-sleep) below 800ms for
- 1-wire 18B20 (possibly 2 sensors at FULL 12 bits resolution)
- BMP180 temperature
- BMP180 pressure
- battery voltage
- timing info

Thanks again
Amicalement ;)
User avatar
By torntrousers
#60652
kas wrote:This is my ThingSpeak connection function, any comments ??
[code]boolean updateThingSpeak(String tsData) { //Thingspeak Stuff
if (client.connect(eTSpeak.c_str(), 80)) { // Make a TCP connection to remote host
client.print("POST /update HTTP/1.1\n");
client.print("Host: "+eTSpeak+"\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+eApiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
client.stop();


I've been told its better to try to minimize the client.print calls as each might do an actual I/O which is slow, so for example concat the headers together and then send them altogether with a single client.print.