Compare commits

..

7 Commits

Author SHA1 Message Date
Gunnar Skjold
c3fa618ab2 Fixed build problem 2021-01-09 09:50:20 +01:00
Gunnar Skjold
7713ae8566 Trying to fix GitHub Actions build issue 2021-01-09 09:36:20 +01:00
Gunnar Skjold
7ae860ec72 Fixed incorrect reading of analog temperature 2021-01-09 09:33:09 +01:00
Gunnar Skjold
376008a735 Merge pull request #96 from kallemooo/fixFromHex
Changed fromHex() to use an supplied buffer
2021-01-04 09:58:32 +01:00
Karl Thorén
feed10184b Changed fromHex() to use an supplied buffer
Solves the problem with returning a pointer to local variable.

Signed-off-by: Karl Thorén <karl.h.thoren@gmail.com>
2020-12-27 16:29:53 +01:00
Gunnar Skjold
59ca29f6a8 Update README.md 2020-09-25 06:46:16 +02:00
Gunnar Skjold
644a3fa40b Fixed factory reset 2020-09-05 20:03:06 +02:00
8 changed files with 30 additions and 19 deletions

View File

@@ -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.

View File

@@ -1,4 +1,4 @@
name=HANreader
name=HanReader
version=1.0.1
author=roarfred
maintainer=roarfred <not@important.com>

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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, ...);