mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-20 10:04:59 +00:00
Option to send raw data frame to MQTT
This commit is contained in:
parent
77ce5d8e90
commit
fb8d9e51a6
@ -28,6 +28,7 @@ ADC_MODE(ADC_VCC);
|
||||
#include <DNSServer.h>
|
||||
#include <lwip/apps/sntp.h>
|
||||
|
||||
#include "hexutils.h"
|
||||
#include "HwTools.h"
|
||||
#include "entsoe/EntsoeApi.h"
|
||||
|
||||
@ -785,8 +786,10 @@ bool readHanPort() {
|
||||
debugD("Authentication tag:");
|
||||
debugPrint(hc->authentication_tag, 0, 12);
|
||||
}
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), toHex(buf, len));
|
||||
}
|
||||
len = 0;
|
||||
while(hanSerial->available()) hanSerial->read();
|
||||
if(pos > 0) {
|
||||
debugD("Valid data, start at byte %d", pos);
|
||||
data = IEC6205675(((char *) (buf)) + pos, meterState.getMeterType(), meterConfig.distributionSystem, timestamp, hc);
|
||||
@ -842,6 +845,9 @@ bool readHanPort() {
|
||||
}
|
||||
} else if(currentMeterType == 2) {
|
||||
String payload = hanSerial->readString();
|
||||
if(mqttEnabled && mqtt != NULL && mqttHandler == NULL) {
|
||||
mqtt->publish(topic.c_str(), payload);
|
||||
}
|
||||
data = IEC6205621(payload);
|
||||
if(data.getListType() == 0) {
|
||||
currentMeterType = 1;
|
||||
@ -1047,7 +1053,20 @@ void MQTT_connect() {
|
||||
mqtt->disconnect();
|
||||
yield();
|
||||
} else {
|
||||
mqtt = new MQTTClient(512);
|
||||
uint16_t size = 128;
|
||||
switch(mqttConfig.payloadFormat) {
|
||||
case 0: // JSON
|
||||
size = 768;
|
||||
break;
|
||||
case 3: // Domoticz
|
||||
size = 256;
|
||||
break;
|
||||
case 255: // Raw frame
|
||||
size = 1024;
|
||||
break;
|
||||
}
|
||||
|
||||
mqtt = new MQTTClient(size);
|
||||
ws.setMqtt(mqtt);
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ String toHex(uint8_t* in) {
|
||||
return toHex(in, sizeof(in)*2);
|
||||
}
|
||||
|
||||
String toHex(uint8_t* in, uint8_t size) {
|
||||
String toHex(uint8_t* in, uint16_t size) {
|
||||
String hex;
|
||||
for(int i = 0; i < size; i++) {
|
||||
if(in[i] < 0x10) {
|
||||
@ -16,7 +16,7 @@ String toHex(uint8_t* in, uint8_t size) {
|
||||
return hex;
|
||||
}
|
||||
|
||||
void fromHex(uint8_t *out, String in, uint8_t size) {
|
||||
void fromHex(uint8_t *out, String in, uint16_t size) {
|
||||
for(int i = 0; i < size*2; i += 2) {
|
||||
out[i/2] = strtol(in.substring(i, i+2).c_str(), 0, 16);
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
String toHex(uint8_t* in);
|
||||
String toHex(uint8_t* in, uint8_t size);
|
||||
void fromHex(uint8_t *out, String in, uint8_t size);
|
||||
String toHex(uint8_t* in, uint16_t size);
|
||||
void fromHex(uint8_t *out, String in, uint16_t size);
|
||||
|
||||
#endif
|
||||
@ -551,6 +551,7 @@ void AmsWebServer::configMqttHtml() {
|
||||
for(int i = 0; i<4; i++) {
|
||||
html.replace("{f" + String(i) + "}", mqtt.payloadFormat == i ? "selected" : "");
|
||||
}
|
||||
html.replace("{f255}", mqtt.payloadFormat == 255 ? "selected" : "");
|
||||
|
||||
html.replace("{s}", mqtt.ssl ? "checked" : "");
|
||||
|
||||
|
||||
@ -59,9 +59,10 @@
|
||||
</div>
|
||||
<select id="f" class="form-control mc" name="f">
|
||||
<option value="0" {f0}>JSON</option>
|
||||
<option value="1" {f1}>Raw (minimal)</option>
|
||||
<option value="2" {f2}>Raw (full)</option>
|
||||
<option value="1" {f1}>Raw values (minimal)</option>
|
||||
<option value="2" {f2}>Raw values (full)</option>
|
||||
<option value="3" {f3}>Domoticz</option>
|
||||
<option value="255" {f255}>Raw data (bytes)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user