mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-26 04:07:57 +00:00
Cleanup and fix bugs found during testing
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
#ifndef _AMSTOMQTTBRIDGE_H
|
||||||
|
#define _AMSTOMQTTBRIDGE_H
|
||||||
|
|
||||||
#define WIFI_CONNECTION_TIMEOUT 30000;
|
#define WIFI_CONNECTION_TIMEOUT 30000;
|
||||||
|
|
||||||
#define INVALID_BUTTON_PIN 0xFFFFFFFF
|
#define INVALID_BUTTON_PIN 0xFFFFFFFF
|
||||||
@@ -14,7 +17,6 @@
|
|||||||
#define LED_PIN 2 // The blue on-board LED of the ESP8266 custom AMS board
|
#define LED_PIN 2 // The blue on-board LED of the ESP8266 custom AMS board
|
||||||
#define LED_ACTIVE_HIGH 0
|
#define LED_ACTIVE_HIGH 0
|
||||||
#define AP_BUTTON_PIN 0
|
#define AP_BUTTON_PIN 0
|
||||||
#define TEMP_SENSOR_PIN 5
|
|
||||||
|
|
||||||
#if DEBUG_MODE
|
#if DEBUG_MODE
|
||||||
#define SOFTWARE_SERIAL 1
|
#define SOFTWARE_SERIAL 1
|
||||||
@@ -29,7 +31,6 @@ HardwareSerial *hanSerial = &Serial;
|
|||||||
#define LED_PIN 5
|
#define LED_PIN 5
|
||||||
#define LED_ACTIVE_HIGH 0
|
#define LED_ACTIVE_HIGH 0
|
||||||
#define AP_BUTTON_PIN 4
|
#define AP_BUTTON_PIN 4
|
||||||
#define TEMP_SENSOR_PIN 14
|
|
||||||
|
|
||||||
#define SOFTWARE_SERIAL 1
|
#define SOFTWARE_SERIAL 1
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
@@ -40,7 +41,6 @@ SoftwareSerial *hanSerial = new SoftwareSerial(GPIO_NUM_21);
|
|||||||
#define LED_PIN D4
|
#define LED_PIN D4
|
||||||
#define LED_ACTIVE_HIGH 0
|
#define LED_ACTIVE_HIGH 0
|
||||||
#define AP_BUTTON_PIN D2
|
#define AP_BUTTON_PIN D2
|
||||||
#define TEMP_SENSOR_PIN D5
|
|
||||||
|
|
||||||
#define SOFTWARE_SERIAL 1
|
#define SOFTWARE_SERIAL 1
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
@@ -63,3 +63,5 @@ HardwareSerial *hanSerial = &Serial;
|
|||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
SoftwareSerial *hanSerial = new SoftwareSerial(5);
|
SoftwareSerial *hanSerial = new SoftwareSerial(5);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -141,6 +141,8 @@ bool buttonActive = false;
|
|||||||
unsigned long longPressTime = 5000;
|
unsigned long longPressTime = 5000;
|
||||||
bool longPressActive = false;
|
bool longPressActive = false;
|
||||||
|
|
||||||
|
bool wifiConnected = false;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (digitalRead(AP_BUTTON_PIN) == LOW) {
|
if (digitalRead(AP_BUTTON_PIN) == LOW) {
|
||||||
if (buttonActive == false) {
|
if (buttonActive == false) {
|
||||||
@@ -170,8 +172,13 @@ void loop() {
|
|||||||
|
|
||||||
// Reconnect to WiFi and MQTT as needed
|
// Reconnect to WiFi and MQTT as needed
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
|
wifiConnected = false;
|
||||||
WiFi_connect();
|
WiFi_connect();
|
||||||
} else {
|
} else {
|
||||||
|
if(!wifiConnected) {
|
||||||
|
wifiConnected = true;
|
||||||
|
if(debugger) debugger->println("Successfully connected to WiFi!");
|
||||||
|
}
|
||||||
if (!config.getMqttHost().isEmpty()) {
|
if (!config.getMqttHost().isEmpty()) {
|
||||||
mqtt.loop();
|
mqtt.loop();
|
||||||
yield();
|
yield();
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
#include "HwTools.h"
|
#include "HwTools.h"
|
||||||
|
|
||||||
|
|
||||||
double HwTools::getVcc() {
|
double HwTools::getVcc() {
|
||||||
#if defined(ARDUINO_ESP8266_WEMOS_D1MINI)
|
#if defined(ARDUINO_ESP8266_WEMOS_D1MINI)
|
||||||
return (((double) ESP.getVcc()) / 1024) * 1.1; // This board has a voltage divider on VCC, add 10%
|
return (((double) ESP.getVcc()) / 900); // This board has a voltage divider on VCC. Yes, 900 is correct
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
return ((double) ESP.getVcc()) / 1024;
|
return ((double) ESP.getVcc()) / 1024;
|
||||||
#endif
|
#endif
|
||||||
@@ -15,7 +14,7 @@ double HwTools::getTemperature() {
|
|||||||
#if defined TEMP_SENSOR_PIN
|
#if defined TEMP_SENSOR_PIN
|
||||||
if(!tempSensorInit) {
|
if(!tempSensorInit) {
|
||||||
tempSensor->begin();
|
tempSensor->begin();
|
||||||
delay(25);
|
delay(50);
|
||||||
tempSensor->requestTemperatures();
|
tempSensor->requestTemperatures();
|
||||||
hasTempSensor = tempSensor->getTempCByIndex(0) != DEVICE_DISCONNECTED_C;
|
hasTempSensor = tempSensor->getTempCByIndex(0) != DEVICE_DISCONNECTED_C;
|
||||||
tempSensorInit = true;
|
tempSensorInit = true;
|
||||||
|
|||||||
@@ -12,16 +12,24 @@
|
|||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
|
|
||||||
|
#if HW_ROARFRED
|
||||||
|
#define TEMP_SENSOR_PIN 5
|
||||||
|
#elif defined(ARDUINO_LOLIN_D32)
|
||||||
|
#define TEMP_SENSOR_PIN 14
|
||||||
|
#elif defined(ARDUINO_ESP8266_WEMOS_D1MINI)
|
||||||
|
#define TEMP_SENSOR_PIN D5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class HwTools {
|
class HwTools {
|
||||||
public:
|
public:
|
||||||
static double getVcc();
|
double getVcc();
|
||||||
static double getTemperature();
|
double getTemperature();
|
||||||
|
|
||||||
HwTools() {
|
HwTools() {
|
||||||
#if defined TEMP_SENSOR_PIN
|
|
||||||
oneWire = new OneWire(TEMP_SENSOR_PIN);
|
oneWire = new OneWire(TEMP_SENSOR_PIN);
|
||||||
tempSensor = new DallasTemperature(this->oneWire);
|
tempSensor = new DallasTemperature(this->oneWire);
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
bool tempSensorInit, hasTempSensor;
|
bool tempSensorInit, hasTempSensor;
|
||||||
|
|||||||
@@ -159,6 +159,10 @@ void AmsWebServer::indexHtml() {
|
|||||||
double vcc = hw.getVcc();
|
double vcc = hw.getVcc();
|
||||||
html.replace("${vcc}", vcc > 0 ? String(vcc, 2) : "");
|
html.replace("${vcc}", vcc > 0 ? String(vcc, 2) : "");
|
||||||
|
|
||||||
|
double temp = hw.getTemperature();
|
||||||
|
html.replace("${temp}", temp > 0 ? String(temp, 1) : "");
|
||||||
|
html.replace("${display.temp}", temp != DEVICE_DISCONNECTED_C ? "" : "none");
|
||||||
|
|
||||||
float rssi = WiFi.RSSI();
|
float rssi = WiFi.RSSI();
|
||||||
rssi = isnan(rssi) ? -100.0 : rssi;
|
rssi = isnan(rssi) ? -100.0 : rssi;
|
||||||
html.replace("${wifi.rssi}", vcc > 0 ? String(rssi, 0) : "");
|
html.replace("${wifi.rssi}", vcc > 0 ? String(rssi, 0) : "");
|
||||||
@@ -327,6 +331,9 @@ void AmsWebServer::dataJson() {
|
|||||||
double vcc = hw.getVcc();
|
double vcc = hw.getVcc();
|
||||||
json["vcc"] = vcc > 0 ? vcc : 0;
|
json["vcc"] = vcc > 0 ? vcc : 0;
|
||||||
|
|
||||||
|
double temp = hw.getTemperature();
|
||||||
|
json["temp"] = temp;
|
||||||
|
|
||||||
json.createNestedObject("wifi");
|
json.createNestedObject("wifi");
|
||||||
float rssi = WiFi.RSSI();
|
float rssi = WiFi.RSSI();
|
||||||
rssi = isnan(rssi) ? -100.0 : rssi;
|
rssi = isnan(rssi) ? -100.0 : rssi;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="boot.css"/>
|
<link rel="stylesheet" type="text/css" href="boot.css"/>
|
||||||
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css"/>
|
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css"/>
|
||||||
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
|
||||||
<script src="gaugemeter.js"></script>
|
<script src="gaugemeter.js"></script>
|
||||||
<style>
|
<style>
|
||||||
.bg-purple {
|
.bg-purple {
|
||||||
@@ -148,7 +149,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div style="display: ${display.production};">
|
<div class="text-center" style="display: ${display.production};">
|
||||||
<div id="P" class="SimpleMeter" style="display: inline;">
|
<div id="P" class="SimpleMeter" style="display: inline;">
|
||||||
${data.PO} W
|
${data.PO} W
|
||||||
</div>
|
</div>
|
||||||
@@ -170,6 +171,15 @@
|
|||||||
<div class="col-6">Vcc</div>
|
<div class="col-6">Vcc</div>
|
||||||
<div class="col-6 text-right"><span id="vcc">${vcc}</span> V</div>
|
<div class="col-6 text-right"><span id="vcc">${vcc}</span> V</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row" style="display: ${display.temp};">
|
||||||
|
<div class="col-6">Temperature</div>
|
||||||
|
<div class="col-6 text-right"><span id="temp">${temp}</span> °C</div>
|
||||||
|
</div>
|
||||||
|
<div class="row" style="display: none;">
|
||||||
|
<div class="col-6">Uptime</div>
|
||||||
|
<div class="col-6 text-right"><span id="currentMillis">${currentMillis}</span></div>
|
||||||
|
</div>
|
||||||
|
<hr/>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">SSID</div>
|
<div class="col-6">SSID</div>
|
||||||
<div class="col-6 text-right"><span id="ssid">${wifi.ssid}</span></div>
|
<div class="col-6 text-right"><span id="ssid">${wifi.ssid}</span></div>
|
||||||
@@ -232,6 +242,11 @@ var fetch = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(window.moment) {
|
||||||
|
$('#currentMillis').html(moment.duration(parseInt(json.currentMillis)).humanize());
|
||||||
|
$('#currentMillis').closest('.row').show();
|
||||||
|
}
|
||||||
|
|
||||||
if(json.status) {
|
if(json.status) {
|
||||||
for(var id in json.status) {
|
for(var id in json.status) {
|
||||||
var badge = json.status[id];
|
var badge = json.status[id];
|
||||||
|
|||||||
Reference in New Issue
Block a user