Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By danbicks
#16208 This is really good work, do you have a circuit diagram of the setup, what a>d are you using here? the Esp01 has no adc broken out on the pins, have you modified the board to breakout this pin?

Good work.

PS: What is the spec on the solar panel etc?

Dans
User avatar
By torntrousers
#16288
danbicks wrote:Have you a copy of the full sketch including battery monitoring, would be brill to have a tinker with.


Here is the sketch, its nothing special and just a modified one of the client smaples that uses the readVdd system call to get the supply voltage.

Code: Select all#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
extern "C" {
  #include "user_interface.h"
  uint16 readvdd33(void);
}

const char* ssid = "BTHub5-72W5";
const char* password = "xxxxxx";

const char* host = "data.sparkfun.com";
const char* streamId   = "YGXNzYOwjWU15Ly5GOgb";
const char* privateKey = "xxxxxx";

const unsigned long SLEEP_INFTERVAL = 15 * 60 * 1000 * 1000; // 15 minutes
//const unsigned long SLEEP_INFTERVAL = 20 * 1000 * 1000; // 20 sec

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 0

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

float vdd;
 
void setup() {
  vdd = readvdd33() / 1000.0;

  Serial.begin(115200);
  Serial.println();

  Serial.print("Vdd: ");
  Serial.println(vdd, 2);

  sensors.begin();

  initWifi();

  sendHello();

  Serial.print("up time: ");
  Serial.print(millis());

  Serial.print(", deep sleep for ");
  Serial.print(SLEEP_INFTERVAL / 1000000);
  Serial.println(" secs...");
  system_deep_sleep_set_option(1);
  system_deep_sleep(SLEEP_INFTERVAL - micros()); // deep sleep for 15 minutes minus how long this reading was up for

  delay(1000); //
}

void loop() {
   // should never get here
}

void sendHello() {
  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  while (!client.connect(host, httpPort)) {
    Serial.println("connection failed, retrying...");
  }

  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("request temp");
  float temp = sensors.getTempCByIndex(0);
  Serial.print("Temperature for the device 1 (index 0) is: ");
  Serial.println(temp);

  String url = "/input/";
  url += streamId;
  url += "?private_key=";
  url += privateKey;
 
  Serial.print("Requesting URL: ");
  Serial.println(url);
 
  client.print(String("GET ") + url);
  client.print("&temp=");
  client.print(temp,1);
  client.print("&vdd=");
  client.print(vdd,1);
  client.print(String(" HTTP/1.1\r\n") +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(10);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  Serial.println();
  Serial.println("closing connection");
//  client.stop();
}

void initWifi() {
   Serial.print("current connect:{ ");
   Serial.println(WiFi.SSID());
   if (strcmp (WiFi.SSID(),ssid) != 0) {
      Serial.print("Connecting to ");
      Serial.println(ssid);
 
      WiFi.begin(ssid, password);
      wifi_station_set_auto_connect(true);
 
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
  }

  Serial.println("");
  Serial.print("WiFi connected in: "); 
  Serial.println(millis());

  Serial.println();
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}


Checking a few times with a multimeter readVdd seems to be reasonably stable and consistently gives about 0.1v higher than the actually batter voltage shown by the multimeter.

The solar power pack just clips together (can't be anything like as weather proof as they make out) and the ESP-01 power pins are directly wired to the LIPO battery:
You do not have the required permissions to view the files attached to this post.