Good work.
PS: What is the spec on the solar panel etc?
Dans
Explore... Chat... Share...
Moderator: igrr
danbicks wrote:Have you a copy of the full sketch including battery monitoring, would be brill to have a tinker with.
#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());
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]