add oled support
This commit is contained in:
@@ -4,6 +4,10 @@
|
|||||||
#define JSON_CONFIG_FILE "/config.json"
|
#define JSON_CONFIG_FILE "/config.json"
|
||||||
#define TUBE_NAME "J305"
|
#define TUBE_NAME "J305"
|
||||||
#define TUBE_FACTOR 0.00812
|
#define TUBE_FACTOR 0.00812
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
#define i2c_Address 0x3c
|
||||||
|
#define OLED_RESET -1
|
||||||
|
|
||||||
#include <ESP_DoubleResetDetector.h>
|
#include <ESP_DoubleResetDetector.h>
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
@@ -12,6 +16,11 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SH110X.h>
|
||||||
|
|
||||||
DoubleResetDetector* drd;
|
DoubleResetDetector* drd;
|
||||||
|
|
||||||
@@ -19,6 +28,8 @@ WiFiClient espClient; // connection for MQTT
|
|||||||
WiFiClient espClient2; // connection fot HTTP Client
|
WiFiClient espClient2; // connection fot HTTP Client
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
|
|
||||||
|
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
// Initialize LittleFS
|
// Initialize LittleFS
|
||||||
void initLittleFS() {
|
void initLittleFS() {
|
||||||
if (!LittleFS.begin(true)) {
|
if (!LittleFS.begin(true)) {
|
||||||
@@ -53,11 +64,17 @@ void ICACHE_RAM_ATTR handleInterrupt() {
|
|||||||
GeigerCounts++;
|
GeigerCounts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* ntpServer = "europe.pool.ntp.org";
|
||||||
|
const long gmtOffset_sec = 3600; // GMT +1 = 3600
|
||||||
|
const int daylightOffset_sec = 3600;
|
||||||
|
|
||||||
String GMCMap_Request_payload = "http://www.GMCmap.com/log2.asp";
|
String GMCMap_Request_payload = "http://www.GMCmap.com/log2.asp";
|
||||||
String GMCMap_Request = "";
|
String GMCMap_Request = "";
|
||||||
String GMCMap_Data = "";
|
String GMCMap_Data = "";
|
||||||
String GMCMap = "NONE";
|
String GMCMap = "NONE";
|
||||||
|
|
||||||
|
struct tm timeinfo;
|
||||||
|
|
||||||
void saveConfigFile()
|
void saveConfigFile()
|
||||||
{
|
{
|
||||||
Serial.println(F("Saving config"));
|
Serial.println(F("Saving config"));
|
||||||
@@ -152,6 +169,38 @@ void reconnect() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcdPrint(String x) {
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(SH110X_WHITE);
|
||||||
|
display.setCursor(0, 10);
|
||||||
|
display.println(x);
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcdUpdate() {
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(SH110X_WHITE);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println(printLocalTime());
|
||||||
|
display.println("uSv/h: " + String(buf2));
|
||||||
|
display.println("CPM: " + String(buf));
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
String printLocalTime()
|
||||||
|
{
|
||||||
|
//if(!getLocalTime(&timeinfo)){
|
||||||
|
// Serial.println("Failed to obtain time");
|
||||||
|
// return "Failed to obtain time";
|
||||||
|
//}
|
||||||
|
char buffer[80];
|
||||||
|
//strftime(buffer, 80, "%H:%M:%S %d-%m-%Y ", &timeinfo);
|
||||||
|
strftime(buffer, 80, "%H:%M <|> %d-%m-%Y ", &timeinfo);
|
||||||
|
return String(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
|
// WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
|
||||||
// it is a good practice to make sure your code sets wifi mode how you want it.
|
// it is a good practice to make sure your code sets wifi mode how you want it.
|
||||||
@@ -161,6 +210,10 @@ void setup() {
|
|||||||
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING );
|
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING );
|
||||||
initLittleFS();
|
initLittleFS();
|
||||||
|
|
||||||
|
display.begin(i2c_Address, true);
|
||||||
|
|
||||||
|
lcdPrint("Geiger Interace");
|
||||||
|
|
||||||
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
|
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
|
||||||
bool forceConfig = false;
|
bool forceConfig = false;
|
||||||
if (drd->detectDoubleReset()) {
|
if (drd->detectDoubleReset()) {
|
||||||
@@ -205,7 +258,6 @@ void setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//tutaj bez sensu
|
|
||||||
strcpy(mqttServer, custom_mqttServer.getValue());
|
strcpy(mqttServer, custom_mqttServer.getValue());
|
||||||
strcpy(mqttUser, custom_mqttUser.getValue());
|
strcpy(mqttUser, custom_mqttUser.getValue());
|
||||||
strcpy(mqttPass, custom_mqttPass.getValue());
|
strcpy(mqttPass, custom_mqttPass.getValue());
|
||||||
@@ -228,6 +280,9 @@ void setup() {
|
|||||||
|
|
||||||
client.setServer(mqttServer, 1883);
|
client.setServer(mqttServer, 1883);
|
||||||
|
|
||||||
|
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
|
||||||
|
printLocalTime();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -252,10 +307,16 @@ void loop() {
|
|||||||
client.publish("esp32/uSv", buf2);
|
client.publish("esp32/uSv", buf2);
|
||||||
GeigerCounts = 0;
|
GeigerCounts = 0;
|
||||||
mold += 60000;
|
mold += 60000;
|
||||||
|
lcdUpdate();
|
||||||
}
|
}
|
||||||
client.loop();
|
client.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLocalTime(&timeinfo);
|
||||||
|
if (timeinfo.tm_sec == 0){
|
||||||
|
lcdUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
// if GMC IDs provided
|
// if GMC IDs provided
|
||||||
if (String(gmcAccountID) != "") {
|
if (String(gmcAccountID) != "") {
|
||||||
currentMillis = millis();
|
currentMillis = millis();
|
||||||
|
|||||||
Reference in New Issue
Block a user