commit
0c210d2ff0
@ -50,6 +50,9 @@ LoLin32lite + [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-L
|
|||||||
- Generic ESP32
|
- Generic ESP32
|
||||||
|
|
||||||
Depending on board hardware following features are supported:
|
Depending on board hardware following features are supported:
|
||||||
|
- LoRaWAN communication, supporting various payload formats (see enclosed .js converters)
|
||||||
|
- MQTT communication via TCP/IP and Ethernet interface (note: payload transmitted over MQTT will be base64 encoded)
|
||||||
|
- SPI serial communication to a local host
|
||||||
- LED (shows power & status)
|
- LED (shows power & status)
|
||||||
- OLED Display (shows detailed status)
|
- OLED Display (shows detailed status)
|
||||||
- RGB LED (shows colorized status)
|
- RGB LED (shows colorized status)
|
||||||
@ -62,7 +65,6 @@ Depending on board hardware following features are supported:
|
|||||||
- Switch external power / battery
|
- Switch external power / battery
|
||||||
- LED Matrix display (similar to [this 64x16 model](https://www.instructables.com/id/64x16-RED-LED-Marquee/), can be ordered on [Aliexpress](https://www.aliexpress.com/item/P3-75-dot-matrix-led-module-3-75mm-high-clear-top1-for-text-display-304-60mm/32616683948.html))
|
- LED Matrix display (similar to [this 64x16 model](https://www.instructables.com/id/64x16-RED-LED-Marquee/), can be ordered on [Aliexpress](https://www.aliexpress.com/item/P3-75-dot-matrix-led-module-3-75mm-high-clear-top1-for-text-display-304-60mm/32616683948.html))
|
||||||
- SD-card (see section SD-card here) for logging pax data
|
- SD-card (see section SD-card here) for logging pax data
|
||||||
- Ethernet interface for MQTT communication via TCP/IP
|
|
||||||
|
|
||||||
Target platform must be selected in `platformio.ini`.<br>
|
Target platform must be selected in `platformio.ini`.<br>
|
||||||
Hardware dependent settings (pinout etc.) are stored in board files in /hal directory. If you want to use a ESP32 board which is not yet supported, use hal file generic.h and tailor pin mappings to your needs. Pull requests for new boards welcome.<br>
|
Hardware dependent settings (pinout etc.) are stored in board files in /hal directory. If you want to use a ESP32 board which is not yet supported, use hal file generic.h and tailor pin mappings to your needs. Pull requests for new boards welcome.<br>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "rcommand.h"
|
#include "rcommand.h"
|
||||||
#include <MQTT.h>
|
#include <MQTT.h>
|
||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
|
#include <mbedtls/base64.h>
|
||||||
|
|
||||||
#ifndef MQTT_CLIENTNAME
|
#ifndef MQTT_CLIENTNAME
|
||||||
#define MQTT_CLIENTNAME clientId
|
#define MQTT_CLIENTNAME clientId
|
||||||
@ -17,8 +18,7 @@ uint32_t mqtt_queuewaiting(void);
|
|||||||
void mqtt_queuereset(void);
|
void mqtt_queuereset(void);
|
||||||
void mqtt_client_task(void *param);
|
void mqtt_client_task(void *param);
|
||||||
int mqtt_connect(const char *my_host, const uint16_t my_port);
|
int mqtt_connect(const char *my_host, const uint16_t my_port);
|
||||||
void mqtt_callback(MQTTClient *client, char topic[], char payload[],
|
void mqtt_callback(MQTTClient *client, char *topic, char *payload, int length);
|
||||||
int length);
|
|
||||||
void NetworkEvent(WiFiEvent_t event);
|
void NetworkEvent(WiFiEvent_t event);
|
||||||
esp_err_t mqtt_init(void);
|
esp_err_t mqtt_init(void);
|
||||||
void mqtt_deinit(void);
|
void mqtt_deinit(void);
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
void do_reset(bool warmstart);
|
void do_reset(bool warmstart);
|
||||||
void do_after_reset(void);
|
void do_after_reset(void);
|
||||||
void enter_deepsleep(const uint64_t wakeup_sec, const gpio_num_t wakeup_gpio);
|
void enter_deepsleep(const uint64_t wakeup_sec = 60,
|
||||||
|
const gpio_num_t wakeup_gpio = GPIO_NUM_MAX);
|
||||||
unsigned long long uptime(void);
|
unsigned long long uptime(void);
|
||||||
|
|
||||||
#endif // _RESET_H
|
#endif // _RESET_H
|
@ -47,7 +47,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I
|
|||||||
|
|
||||||
[common]
|
[common]
|
||||||
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
||||||
release_version = 2.1.0
|
release_version = 2.1.1
|
||||||
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
|
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
|
||||||
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
||||||
debug_level = 3
|
debug_level = 3
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
// Hardware related definitions for Pycom LoPy4 Board
|
// Hardware related definitions for Pycom LoPy4 Board
|
||||||
|
|
||||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||||
#define LORA_RST LMIC_UNUSED_PIN // reset pin of lora chip is not wired von LoPy4
|
|
||||||
|
|
||||||
//#defin HAS_SPI 1 // comment out if device shall not send data via SPI
|
//#defin HAS_SPI 1 // comment out if device shall not send data via SPI
|
||||||
// pin definitions for local wired SPI slave interface
|
// pin definitions for local wired SPI slave interface
|
||||||
|
@ -18,9 +18,10 @@
|
|||||||
|
|
||||||
// use interrupts only if LORA_IRQ and LORA_DIO are connected to interrupt
|
// use interrupts only if LORA_IRQ and LORA_DIO are connected to interrupt
|
||||||
// capable and separate GPIO pins on your board, if not don't enable
|
// capable and separate GPIO pins on your board, if not don't enable
|
||||||
#if (LORA_IRQ) != (LORA_IO1)
|
// note: this feature can't be used on ESP32 unless PR #556 of MCCI LMIC was merged
|
||||||
#define LMIC_USE_INTERRUPTS 1
|
//#if (LORA_IRQ) != (LORA_IO1)
|
||||||
#endif
|
//#define LMIC_USE_INTERRUPTS 1
|
||||||
|
//#endif
|
||||||
|
|
||||||
// avoid lmic warning if we don't configure radio in case we haven't one
|
// avoid lmic warning if we don't configure radio in case we haven't one
|
||||||
#if !(defined(CFG_sx1272_radio) || defined(CFG_sx1276_radio))
|
#if !(defined(CFG_sx1272_radio) || defined(CFG_sx1276_radio))
|
||||||
|
@ -102,6 +102,10 @@ void IRAM_ATTR mac_add(uint8_t *paddr, int8_t rssi, snifftype_t sniff_type) {
|
|||||||
|
|
||||||
uint16_t mac_analyze(MacBuffer_t MacBuffer) {
|
uint16_t mac_analyze(MacBuffer_t MacBuffer) {
|
||||||
|
|
||||||
|
uint32_t *mac; // pointer to shortened 4 byte MAC
|
||||||
|
uint32_t saltedmac;
|
||||||
|
uint16_t hashedmac;
|
||||||
|
|
||||||
if ((cfg.rssilimit) &&
|
if ((cfg.rssilimit) &&
|
||||||
(MacBuffer.rssi < cfg.rssilimit)) { // rssi is negative value
|
(MacBuffer.rssi < cfg.rssilimit)) { // rssi is negative value
|
||||||
ESP_LOGI(TAG, "%s RSSI %d -> ignoring (limit: %d)",
|
ESP_LOGI(TAG, "%s RSSI %d -> ignoring (limit: %d)",
|
||||||
@ -124,8 +128,6 @@ uint16_t mac_analyze(MacBuffer_t MacBuffer) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t *mac; // pointer to shortened 4 byte MAC
|
|
||||||
|
|
||||||
// only last 3 MAC Address bytes are used for MAC address anonymization
|
// only last 3 MAC Address bytes are used for MAC address anonymization
|
||||||
// but since it's uint32 we take 4 bytes to avoid 1st value to be 0.
|
// but since it's uint32 we take 4 bytes to avoid 1st value to be 0.
|
||||||
// this gets MAC in msb (= reverse) order, but doesn't matter for hashing it.
|
// this gets MAC in msb (= reverse) order, but doesn't matter for hashing it.
|
||||||
@ -136,12 +138,12 @@ uint16_t mac_analyze(MacBuffer_t MacBuffer) {
|
|||||||
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
|
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
|
||||||
|
|
||||||
// reversed 4 byte MAC added to current salt
|
// reversed 4 byte MAC added to current salt
|
||||||
const uint32_t saltedmac = *mac + salt;
|
saltedmac = *mac + salt;
|
||||||
|
|
||||||
// hashed 4 byte MAC
|
// hashed 4 byte MAC
|
||||||
// to save RAM, we use only lower 2 bytes of hash, since collisions don't
|
// to save RAM, we use only lower 2 bytes of hash, since collisions don't
|
||||||
// matter in our use case
|
// matter in our use case
|
||||||
const uint16_t hashedmac = hash((const char *)&saltedmac, 4);
|
hashedmac = hash((const char *)&saltedmac, 4);
|
||||||
|
|
||||||
auto newmac = macs.insert(hashedmac); // add hashed MAC, if new unique
|
auto newmac = macs.insert(hashedmac); // add hashed MAC, if new unique
|
||||||
bool added =
|
bool added =
|
||||||
|
@ -95,14 +95,23 @@ void mqtt_client_task(void *param) {
|
|||||||
MQTT_KEEPALIVE * 1000 / portTICK_PERIOD_MS) != pdTRUE)
|
MQTT_KEEPALIVE * 1000 / portTICK_PERIOD_MS) != pdTRUE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// prepare data to send
|
// prepare mqtt topic
|
||||||
char buffer[PAYLOAD_BUFFER_SIZE + 3];
|
char topic[16];
|
||||||
snprintf(buffer, msg.MessageSize + 3, "%u/%s", msg.MessagePort,
|
snprintf(topic, 16, "%s/%u", MQTT_OUTTOPIC, msg.MessagePort);
|
||||||
msg.Message);
|
size_t out_len = 0;
|
||||||
|
|
||||||
// send data to mqtt server and delete sent item from queue
|
// get length of base64 encoded message
|
||||||
if (mqttClient.publish(MQTT_OUTTOPIC, buffer)) {
|
mbedtls_base64_encode(NULL, 0, &out_len, (unsigned char *)msg.Message,
|
||||||
ESP_LOGI(TAG, "%d byte(s) sent to MQTT server", msg.MessageSize + 2);
|
msg.MessageSize);
|
||||||
|
|
||||||
|
// base64 encode the message
|
||||||
|
unsigned char encoded[out_len];
|
||||||
|
mbedtls_base64_encode(encoded, out_len, &out_len,
|
||||||
|
(unsigned char *)msg.Message, msg.MessageSize);
|
||||||
|
|
||||||
|
// send encoded message to mqtt server and delete it from queue
|
||||||
|
if (mqttClient.publish(topic, (const char *)encoded, out_len)) {
|
||||||
|
ESP_LOGD(TAG, "%u bytes sent to MQTT server", out_len);
|
||||||
xQueueReceive(MQTTSendQueue, &msg, (TickType_t)0);
|
xQueueReceive(MQTTSendQueue, &msg, (TickType_t)0);
|
||||||
} else
|
} else
|
||||||
ESP_LOGD(TAG, "Couldn't sent message to MQTT server");
|
ESP_LOGD(TAG, "Couldn't sent message to MQTT server");
|
||||||
@ -115,19 +124,29 @@ void mqtt_client_task(void *param) {
|
|||||||
} // while (1)
|
} // while (1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process incoming MQTT messages
|
||||||
|
void mqtt_callback(MQTTClient *client, char *topic, char *payload, int length) {
|
||||||
|
if (strcmp(topic, MQTT_INTOPIC) == 0) {
|
||||||
|
|
||||||
|
// get length of base64 encoded message
|
||||||
|
size_t out_len = 0;
|
||||||
|
mbedtls_base64_decode(NULL, 0, &out_len, (unsigned char *)payload, length);
|
||||||
|
|
||||||
|
// decode the base64 message
|
||||||
|
unsigned char decoded[out_len];
|
||||||
|
mbedtls_base64_decode(decoded, out_len, &out_len, (unsigned char *)payload,
|
||||||
|
length);
|
||||||
|
|
||||||
|
rcommand(decoded, out_len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// enqueue outgoing messages in MQTT send queue
|
// enqueue outgoing messages in MQTT send queue
|
||||||
void mqtt_enqueuedata(MessageBuffer_t *message) {
|
void mqtt_enqueuedata(MessageBuffer_t *message) {
|
||||||
if (xQueueSendToBack(MQTTSendQueue, (void *)message, (TickType_t)0) != pdTRUE)
|
if (xQueueSendToBack(MQTTSendQueue, (void *)message, (TickType_t)0) != pdTRUE)
|
||||||
ESP_LOGW(TAG, "MQTT sendqueue is full");
|
ESP_LOGW(TAG, "MQTT sendqueue is full");
|
||||||
}
|
}
|
||||||
|
|
||||||
// process incoming MQTT messages
|
|
||||||
void mqtt_callback(MQTTClient *client, char topic[], char payload[],
|
|
||||||
int length) {
|
|
||||||
if (strcmp(topic, MQTT_INTOPIC) == 0)
|
|
||||||
rcommand((const uint8_t *)payload, (const uint8_t)length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); }
|
void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); }
|
||||||
|
|
||||||
uint32_t mqtt_queuewaiting(void) {
|
uint32_t mqtt_queuewaiting(void) {
|
||||||
|
@ -81,8 +81,7 @@ void do_after_reset(void) {
|
|||||||
runmode[RTC_runmode]);
|
runmode[RTC_runmode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void enter_deepsleep(const uint64_t wakeup_sec = 60,
|
void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {
|
||||||
gpio_num_t wakeup_gpio = GPIO_NUM_MAX) {
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Preparing to sleep...");
|
ESP_LOGI(TAG, "Preparing to sleep...");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user