mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-03-12 21:44:21 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3fa618ab2 | ||
|
|
7713ae8566 | ||
|
|
7ae860ec72 | ||
|
|
376008a735 | ||
|
|
feed10184b | ||
|
|
59ca29f6a8 | ||
|
|
644a3fa40b |
@@ -38,4 +38,4 @@ It is recommended to use Visual Studio Code with the PlatformIO plugin for devel
|
||||
|
||||
[PlatformIO vscode plugin](https://platformio.org/install/ide?install=vscode)
|
||||
|
||||
Copy the ```platformio-user.ini-example``` to ```platformio-user.ini``` and customize to your preference. The code will adapt to the platform and board set in your profile. If you are using the original board design by [@roarfred](https://github.com/roarfred) use build flag -D HW_ROARFRED=1
|
||||
Copy the ```platformio-user.ini-example``` to ```platformio-user.ini``` and customize to your preference. The code will adapt to the platform and board set in your profile.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name=HANreader
|
||||
name=HanReader
|
||||
version=1.0.1
|
||||
author=roarfred
|
||||
maintainer=roarfred <not@important.com>
|
||||
|
||||
@@ -4,13 +4,13 @@ extra_configs = platformio-user.ini
|
||||
|
||||
[common]
|
||||
framework = arduino
|
||||
lib_deps = HanReader@1.0.1, ArduinoJson@6.14.1, MQTT@2.4.7, DallasTemperature@3.8.1, EspSoftwareSerial@6.7.1, RemoteDebug@3.0.5, Time@1.6
|
||||
lib_deps = file://lib/HanReader, file://lib/Timezone, ArduinoJson@6.14.1, MQTT@2.4.7, DallasTemperature@3.8.1, EspSoftwareSerial@6.7.1, RemoteDebug@3.0.5, Time@1.6
|
||||
|
||||
[env:esp8266]
|
||||
platform = espressif8266@2.5.1
|
||||
board = esp12e
|
||||
framework = ${common.framework}
|
||||
lib_deps = ${common.lib_deps}, mbedtls
|
||||
lib_deps = ${common.lib_deps}, file://lib/mbedtls
|
||||
extra_scripts =
|
||||
pre:scripts/addversion.py
|
||||
scripts/makeweb.py
|
||||
|
||||
@@ -84,6 +84,7 @@ void AmsConfiguration::clearWifi() {
|
||||
setWifiSsid("");
|
||||
setWifiPassword("");
|
||||
setWifiHostname("");
|
||||
setMdnsEnable(true);
|
||||
clearWifiIp();
|
||||
}
|
||||
|
||||
@@ -305,12 +306,14 @@ void AmsConfiguration::setSendUnknown(bool sendUnknown) {
|
||||
}
|
||||
|
||||
void AmsConfiguration::clearMeter() {
|
||||
uint8_t blankKey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
setMeterType(0);
|
||||
setDistributionSystem(0);
|
||||
setMainFuse(0);
|
||||
setProductionCapacity(0);
|
||||
setMeterEncryptionKey(nullptr);
|
||||
setMeterAuthenticationKey(nullptr);
|
||||
setMeterEncryptionKey(blankKey);
|
||||
setMeterAuthenticationKey(blankKey);
|
||||
setSubstituteMissing(false);
|
||||
setSendUnknown(false);
|
||||
}
|
||||
|
||||
@@ -327,8 +327,8 @@ private:
|
||||
0, // Distribution system
|
||||
0, // Main fuse
|
||||
0, // Production capacity
|
||||
{}, // Encryption key
|
||||
{}, // Authentication key
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // Encryption key
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // Authentication key
|
||||
false, // Substitute
|
||||
false, // Send unknown
|
||||
false, // Debug telnet
|
||||
|
||||
@@ -176,12 +176,11 @@ double HwTools::getTemperature() {
|
||||
double HwTools::getTemperatureAnalog() {
|
||||
if(tempAnalogSensorPin != 0xFF) {
|
||||
float adcCalibrationFactor = 1.06587;
|
||||
int adcRead = analogRead(tempAnalogSensorPin);
|
||||
int volts;
|
||||
#if defined(ESP8266)
|
||||
volts = (analogRead(vccPin) / 1024.0) * 3.3;
|
||||
volts = (analogRead(tempAnalogSensorPin) / 1024.0) * 3.3;
|
||||
#elif defined(ESP32)
|
||||
volts = (analogRead(vccPin) / 4095.0) * 3.3;
|
||||
volts = (analogRead(tempAnalogSensorPin) / 4095.0) * 3.3;
|
||||
#endif
|
||||
return ((volts * adcCalibrationFactor) - 0.4) / 0.0195;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,9 @@ void AmsWebServer::temperaturePost() {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
debugger->printf("Addr: %s, name: %s\n", address.c_str(), name.c_str());
|
||||
}
|
||||
config->updateTempSensorConfig(fromHex(address, 8), name.c_str(), common);
|
||||
uint8_t hexStr[8];
|
||||
fromHex(hexStr, address, 8);
|
||||
config->updateTempSensorConfig(hexStr, name.c_str(), common);
|
||||
delay(1);
|
||||
}
|
||||
|
||||
@@ -343,12 +345,10 @@ String AmsWebServer::toHex(uint8_t* in, uint8_t size) {
|
||||
return hex;
|
||||
}
|
||||
|
||||
uint8_t* AmsWebServer::fromHex(String in, uint8_t size) {
|
||||
uint8_t ret[size];
|
||||
void AmsWebServer::fromHex(uint8_t *out, String in, uint8_t size) {
|
||||
for(int i = 0; i < size*2; i += 2) {
|
||||
ret[i/2] = strtol(in.substring(i, i+2).c_str(), 0, 16);
|
||||
out[i/2] = strtol(in.substring(i, i+2).c_str(), 0, 16);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AmsWebServer::configWifiHtml() {
|
||||
@@ -786,13 +786,18 @@ void AmsWebServer::handleSave() {
|
||||
String encryptionKeyHex = server.arg("meterEncryptionKey");
|
||||
if(!encryptionKeyHex.isEmpty()) {
|
||||
encryptionKeyHex.replace("0x", "");
|
||||
config->setMeterEncryptionKey(fromHex(encryptionKeyHex, 16));
|
||||
uint8_t hexStr[16];
|
||||
fromHex(hexStr, encryptionKeyHex, 16);
|
||||
config->setMeterEncryptionKey(hexStr);
|
||||
}
|
||||
printD("Meter 8");
|
||||
|
||||
String authenticationKeyHex = server.arg("meterAuthenticationKey");
|
||||
if(!authenticationKeyHex.isEmpty()) {
|
||||
authenticationKeyHex.replace("0x", "");
|
||||
config->setMeterAuthenticationKey(fromHex(authenticationKeyHex, 16));
|
||||
uint8_t hexStr[16];
|
||||
fromHex(hexStr, encryptionKeyHex, 16);
|
||||
config->setMeterAuthenticationKey(hexStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1403,9 +1408,13 @@ void AmsWebServer::factoryResetHtml() {
|
||||
}
|
||||
|
||||
void AmsWebServer::factoryResetPost() {
|
||||
printD("Performing factory reset");
|
||||
if(server.hasArg("perform") && server.arg("perform") == "true") {
|
||||
printD("Formatting SPIFFS");
|
||||
SPIFFS.format();
|
||||
printD("Clearing configuration");
|
||||
config->clear();
|
||||
printD("Setting restart flag and redirecting");
|
||||
performRestart = true;
|
||||
server.sendHeader("Location","/restart-wait");
|
||||
server.send(303);
|
||||
|
||||
@@ -107,7 +107,7 @@ private:
|
||||
void notFound();
|
||||
|
||||
String toHex(uint8_t* in, uint8_t size);
|
||||
uint8_t* fromHex(String in, uint8_t size);
|
||||
void fromHex(uint8_t *out, String in, uint8_t size);
|
||||
|
||||
void printD(String fmt, ...);
|
||||
void printI(String fmt, ...);
|
||||
|
||||
Reference in New Issue
Block a user