configuration
This commit is contained in:
parent
3c25a7d9e1
commit
0b1c6217c4
@ -37,7 +37,7 @@ BUILD_DIR = build
|
||||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
User/Src/oled.c User/Src/cmdHandler.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/ports.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
|
||||
User/Src/config.c User/Src/oled.c User/Src/cmdHandler.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/ports.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
|
||||
libmbus/mbus/mbus-protocol.c \
|
||||
Core/Src/main.c \
|
||||
Core/Src/gpio.c \
|
||||
|
@ -8,12 +8,15 @@
|
||||
typedef struct __attribute__((__packed__)) s_configBlock {
|
||||
char deviceName[16];
|
||||
uint8_t macAddress[6];
|
||||
char brokerName[64];
|
||||
char watchdogTopic[64];
|
||||
char startupTopic[64];
|
||||
char statusTopic[64];
|
||||
char mbusDataTopic[64];
|
||||
char syslogServerName[64];
|
||||
} t_configBlock;
|
||||
|
||||
void configInit();
|
||||
t_configBlock* getConfig();
|
||||
|
||||
#endif /* _CONFIG_H_ */
|
||||
|
31
cube/User/Src/config.c
Normal file
31
cube/User/Src/config.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <config.h>
|
||||
|
||||
|
||||
/*
|
||||
typedef struct __attribute__((__packed__)) s_configBlock {
|
||||
char deviceName[16];
|
||||
uint8_t macAddress[6];
|
||||
char brokerName[64];
|
||||
char watchdogTopic[64];
|
||||
char startupTopic[64];
|
||||
char statusTopic[64];
|
||||
char mbusDataTopic[64];
|
||||
char syslogServerName[64];
|
||||
} t_configBlock;
|
||||
*/
|
||||
|
||||
t_configBlock defaultConfigBlock = {
|
||||
.deviceName = "MBGW3",
|
||||
.macAddress = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
|
||||
.brokerName = "mqttbroker",
|
||||
.watchdogTopic = "IoT/Watchdog",
|
||||
.startupTopic = "IoT/MBGW3/Startup",
|
||||
.statusTopic = "IoT/MBGW3/Status",
|
||||
.mbusDataTopic = "IoT/MBGW3/Measurement",
|
||||
.syslogServerName = "syslogserver",
|
||||
};
|
||||
|
||||
|
||||
t_configBlock* getConfig() {
|
||||
return &defaultConfigBlock;
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
#include <ringbuffer.h>
|
||||
#include <wizHelper.h>
|
||||
#include <socket.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -26,14 +27,17 @@
|
||||
#define MSGBUFFER_SIZE 256
|
||||
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
extern const uint8_t SYSLOG_SOCK;
|
||||
uint8_t syslogAddr[] = { 172, 16, 11, 15 };
|
||||
uint8_t syslogAddr[4];
|
||||
|
||||
uint8_t singleOctetTXBuffer;
|
||||
|
||||
static ringbuffer_t logBuffer;
|
||||
|
||||
void logInit() {
|
||||
void logInit() {
|
||||
config = getConfig();
|
||||
ringbufferInit(&logBuffer, LOGBUFFER_SIZE);
|
||||
}
|
||||
|
||||
@ -81,7 +85,7 @@ void syslog(char *msg) {
|
||||
state = 1;
|
||||
// no break
|
||||
case 1:
|
||||
if (! wizDnsQuery("syslogserver", syslogAddr)) {
|
||||
if (! wizDnsQuery(config->syslogServerName, syslogAddr)) {
|
||||
disconnect(SYSLOG_SOCK);
|
||||
state = 0;
|
||||
break;
|
||||
|
@ -17,10 +17,17 @@
|
||||
#include <mqttComm.h>
|
||||
#include <oled.h>
|
||||
#include <ringbuffer.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <mbus/mbus-protocol.h>
|
||||
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
/*
|
||||
static const char MBUS_TOPIC[] = "IoT/MBGW3/Measurement";
|
||||
*/
|
||||
|
||||
|
||||
static const uint8_t MBUS_QUERY_CMD = 0x5b;
|
||||
|
||||
@ -130,7 +137,7 @@ static void printError() {
|
||||
coloredMsg(LOG_YELLOW, true, "mbc pe [%d] Error ratio is %.2f",
|
||||
mbusCommHandle.requestId,
|
||||
errorRatio);
|
||||
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\"}",
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\"}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio);
|
||||
oledPrintf(OLED_SCREEN0, "Err:%d/%d %.2f", mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio);
|
||||
@ -231,25 +238,25 @@ static void parseAndPrintFrame() {
|
||||
mbusCommHandle.requestId,
|
||||
errorRatio);
|
||||
if (numOfConsideredFields == 1) {
|
||||
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
"\"Values\":{\"%s\":\"%.1f\"}}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
|
||||
keys[0], values[0]);
|
||||
} else if (numOfConsideredFields == 2) {
|
||||
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
|
||||
keys[0], values[0], keys[1], values[1]);
|
||||
} else if (numOfConsideredFields == 3) {
|
||||
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
|
||||
keys[0], values[0], keys[1], values[1], keys[2], values[2]);
|
||||
} else if (numOfConsideredFields == 4) {
|
||||
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
|
||||
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
|
||||
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
|
||||
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
|
||||
@ -775,6 +782,8 @@ static void mbusCommScheduler(void *handle) {
|
||||
}
|
||||
|
||||
void mbusCommInit() {
|
||||
config = getConfig();
|
||||
|
||||
coloredMsg(LOG_GREEN, true, "mbc mci initializing Meterbus communication");
|
||||
|
||||
// enable receive interrupts
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <mbusComm.h>
|
||||
#include <oled.h>
|
||||
#include <eeprom.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -19,16 +20,19 @@
|
||||
|
||||
extern const uint8_t MQTT_SOCK;
|
||||
|
||||
static t_configBlock *config;
|
||||
|
||||
client_t client;
|
||||
mqttClient_t mqttClient;
|
||||
|
||||
uint8_t brokerAddress[] = { 172, 16, 2, 16 };
|
||||
uint8_t brokerAddress[4];
|
||||
uint16_t brokerPort = 1883;
|
||||
|
||||
/*
|
||||
const static char WatchdogTopic[] = "IoT/Watchdog";
|
||||
const static char StartupTopic[] = "IoT/MBGW3/Startup";
|
||||
const static char StatusTopic[] = "IoT/MBGW3/Status";
|
||||
|
||||
*/
|
||||
|
||||
static uint32_t watchdogCounter = 0;
|
||||
|
||||
@ -44,7 +48,7 @@ void watchdogHandler(void *handle) {
|
||||
|
||||
// typedef void (*callback_t)(char*, uint8_t*, uint16_t);
|
||||
static void mqttCallback(char *topic, uint8_t *payload, uint16_t payloadLength) {
|
||||
if (0 == strcmp(topic, WatchdogTopic)) {
|
||||
if (0 == strcmp(topic, config->watchdogTopic)) {
|
||||
watchdogCounter++;
|
||||
} else {
|
||||
coloredMsg(LOG_GREEN, false, "mqcb: %s : %.*s", topic, payloadLength, payload);
|
||||
@ -61,7 +65,7 @@ static void mqttStatusPublisher(void *handle) {
|
||||
snprintf(buf, sizeof(buf), "{\"uptime\":\"%ld\", \"runningHours\":\"%ld\", \"powerCycles\":\"%ld\", \"tasks\":\"%d\", \"requests\":\"%ld\", \"errors\":\"%ld\", \"octets\":\"%ld\", \"overrun\":\"%ld\", \"framing\":\"%ld\", \"parity\":\"%ld\", \"noise\":\"%ld\"}",
|
||||
uptime, globalDeviceStats->totalRunningHours, globalDeviceStats->totalPowercycles, schTaskCnt(), mbusCommStats->mbusRequestCnt, mbusCommStats->mbusErrorCnt,
|
||||
mbusCommStats->uartOctetCnt, mbusCommStats->uartOverrunCnt, mbusCommStats->uartFramingErrCnt, mbusCommStats->uartParityErrCnt, mbusCommStats->uartNoiseErrCnt);
|
||||
bool res = publish(&mqttClient, StatusTopic, (const uint8_t*)buf, strlen(buf), false);
|
||||
bool res = publish(&mqttClient, config->statusTopic, (const uint8_t*)buf, strlen(buf), false);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, publish returned %d", res);
|
||||
|
||||
oledSetActiveScreen(OLED_SCREEN1);
|
||||
@ -93,7 +97,7 @@ void mqttCommHandler(void *handle) {
|
||||
|
||||
case 1:
|
||||
coloredMsg(LOG_GREEN, false, "mqch, resolving broker name");
|
||||
if (! wizDnsQuery("mqttbroker", brokerAddress)) {
|
||||
if (! wizDnsQuery(config->brokerName, brokerAddress)) {
|
||||
coloredMsg(LOG_GREEN, false, "mqch, query for broker address failed, going to error state");
|
||||
state = 255;
|
||||
}
|
||||
@ -111,7 +115,7 @@ void mqttCommHandler(void *handle) {
|
||||
|
||||
case 2:
|
||||
coloredMsg(LOG_GREEN, false, "mqch, publish start-up");
|
||||
res = publish(&mqttClient, StartupTopic, (const uint8_t*)message, strlen((char*)message), false);
|
||||
res = publish(&mqttClient, config->startupTopic, (const uint8_t*)message, strlen((char*)message), false);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, publish returned %d", res);
|
||||
schAdd(mqttStatusPublisher, NULL, 0, 60000);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, status publisher scheduled");
|
||||
@ -120,7 +124,7 @@ void mqttCommHandler(void *handle) {
|
||||
|
||||
case 3:
|
||||
coloredMsg(LOG_GREEN, false, "mqch, subscribe watchdog");
|
||||
res = subscribe(&mqttClient, WatchdogTopic, MQTTQOS0);
|
||||
res = subscribe(&mqttClient, config->watchdogTopic, MQTTQOS0);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, subscribe returned %d", res);
|
||||
schAdd(watchdogHandler, NULL, 60000, 60000);
|
||||
coloredMsg(LOG_GREEN, false, "mqch, watchdogHandler scheduled");
|
||||
@ -150,6 +154,7 @@ void mqttCommHandler(void *handle) {
|
||||
}
|
||||
|
||||
void mqttCommInit() {
|
||||
config = getConfig();
|
||||
schAdd(mqttCommHandler, NULL, 0, 100);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user