|
@ -1,6 +1,8 @@ |
|
|
//Define DEBUG to get the Output from DEBUG_PRINTLN
|
|
|
//Define DEBUG to get the Output from DEBUG_PRINTLN
|
|
|
#define DEBUG 1 |
|
|
#define DEBUG 1 |
|
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h> |
|
|
|
|
|
|
|
|
//Include Basecamp in this sketch
|
|
|
//Include Basecamp in this sketch
|
|
|
#include <Basecamp.hpp> |
|
|
#include <Basecamp.hpp> |
|
|
#include <Configuration.hpp> |
|
|
#include <Configuration.hpp> |
|
@ -13,6 +15,9 @@ |
|
|
#include <Wire.h> |
|
|
#include <Wire.h> |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#include <WiFiUdp.h> |
|
|
|
|
|
#include <NTPClient.h> |
|
|
|
|
|
|
|
|
#include "main.h" |
|
|
#include "main.h" |
|
|
|
|
|
|
|
|
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); |
|
|
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); |
|
@ -20,6 +25,10 @@ U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, |
|
|
//Create a new Basecamp instance called iot
|
|
|
//Create a new Basecamp instance called iot
|
|
|
Basecamp iot; |
|
|
Basecamp iot; |
|
|
|
|
|
|
|
|
|
|
|
WiFiUDP ntpUDP; |
|
|
|
|
|
NTPClient timeClient(ntpUDP, "de.pool.ntp.org", 3600, 60000); |
|
|
|
|
|
char timeStr[20]; |
|
|
|
|
|
|
|
|
//Variables for the sensor and the battery
|
|
|
//Variables for the sensor and the battery
|
|
|
static const int ResetPin = 35; |
|
|
static const int ResetPin = 35; |
|
|
static const int SensorPin = 32; |
|
|
static const int SensorPin = 32; |
|
@ -29,7 +38,7 @@ int sensorValue = 0; |
|
|
int batteryLimit = 3300; |
|
|
int batteryLimit = 3300; |
|
|
|
|
|
|
|
|
//This is used to control if the ESP should enter sleep mode or not
|
|
|
//This is used to control if the ESP should enter sleep mode or not
|
|
|
bool delaySleep = false; |
|
|
bool delaySleep = true; |
|
|
|
|
|
|
|
|
//Variables for the mqtt packages and topics
|
|
|
//Variables for the mqtt packages and topics
|
|
|
uint16_t statusPacketIdSub = 0; |
|
|
uint16_t statusPacketIdSub = 0; |
|
@ -63,13 +72,6 @@ void setup() { |
|
|
resetToFactoryDefaults(); |
|
|
resetToFactoryDefaults(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
u8g2.begin(); |
|
|
|
|
|
delay(50); |
|
|
|
|
|
u8g2.clearBuffer(); // clear the internal memory
|
|
|
|
|
|
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
|
|
|
|
|
|
u8g2.drawStr(0,10,"Hello World!"); // write something to the internal memory
|
|
|
|
|
|
u8g2.sendBuffer(); // transfer internal memory to the display
|
|
|
|
|
|
|
|
|
|
|
|
//Initialize Basecamp
|
|
|
//Initialize Basecamp
|
|
|
iot.begin(); |
|
|
iot.begin(); |
|
|
|
|
|
|
|
@ -77,6 +79,22 @@ void setup() { |
|
|
DEBUG_PRINTLN("**** CONFIG HAS BEEN MANUALLY RESET ****"); |
|
|
DEBUG_PRINTLN("**** CONFIG HAS BEEN MANUALLY RESET ****"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
u8g2.begin(); |
|
|
|
|
|
delay(50); |
|
|
|
|
|
u8g2.clearBuffer(); // clear the internal memory
|
|
|
|
|
|
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
|
|
|
|
|
|
u8g2.drawStr(2,10,"esp32-node by hendrik"); // write something to the internal memory
|
|
|
|
|
|
if (iot.configuration.get("WifiConfigured") != "True") { |
|
|
|
|
|
u8g2.drawStr(2,30,"NOT CONFIGURED!"); |
|
|
|
|
|
u8g2.drawStr(12,40,"SSID: \"ESP32\""); |
|
|
|
|
|
u8g2.drawStr(12,55,"http://192.168.4.1"); |
|
|
|
|
|
} else { |
|
|
|
|
|
u8g2.drawStr(2,30,"Welcome!"); |
|
|
|
|
|
u8g2.drawStr(12,40,"connecting.."); |
|
|
|
|
|
} |
|
|
|
|
|
u8g2.drawFrame(0,0,u8g2.getDisplayWidth(),u8g2.getDisplayHeight() ); |
|
|
|
|
|
u8g2.sendBuffer(); // transfer internal memory to the display
|
|
|
|
|
|
|
|
|
//Configure the MQTT topics
|
|
|
//Configure the MQTT topics
|
|
|
delaySleepTopic = "esp32-node/cmd/" + iot.hostname + "/delaysleep"; |
|
|
delaySleepTopic = "esp32-node/cmd/" + iot.hostname + "/delaysleep"; |
|
|
statusTopic = "esp32-node/stat/" + iot.hostname + "/status"; |
|
|
statusTopic = "esp32-node/stat/" + iot.hostname + "/status"; |
|
@ -88,6 +106,24 @@ void setup() { |
|
|
iot.mqtt.onConnect(onMqttConnect); |
|
|
iot.mqtt.onConnect(onMqttConnect); |
|
|
iot.mqtt.onPublish(suspendESP); |
|
|
iot.mqtt.onPublish(suspendESP); |
|
|
iot.mqtt.onMessage(onMqttMessage); |
|
|
iot.mqtt.onMessage(onMqttMessage); |
|
|
|
|
|
|
|
|
|
|
|
while (iot.wifi.status() != WL_CONNECTED) { |
|
|
|
|
|
delay(500); |
|
|
|
|
|
Serial.print("."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IPAddress localIP = iot.wifi.getIP(); |
|
|
|
|
|
char ipStr[16]; |
|
|
|
|
|
localIP.toString().toCharArray(ipStr, 16); |
|
|
|
|
|
|
|
|
|
|
|
timeClient.begin(); |
|
|
|
|
|
timeClient.update(); |
|
|
|
|
|
timeClient.getFormattedTime().toCharArray(timeStr, 50); |
|
|
|
|
|
u8g2.clearBuffer(); // clear the internal memory
|
|
|
|
|
|
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
|
|
|
|
|
|
u8g2.drawStr(30, 30, timeStr); |
|
|
|
|
|
u8g2.drawStr(30, 50, ipStr); |
|
|
|
|
|
u8g2.sendBuffer(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -172,5 +208,10 @@ void suspendESP(uint16_t packetId) { |
|
|
|
|
|
|
|
|
void loop() |
|
|
void loop() |
|
|
{ |
|
|
{ |
|
|
|
|
|
timeClient.update(); |
|
|
|
|
|
timeClient.getFormattedTime().toCharArray(timeStr, 50); |
|
|
|
|
|
u8g2.drawStr(30, 30, timeStr); |
|
|
|
|
|
u8g2.sendBuffer(); |
|
|
|
|
|
delay(1000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|