Skip to content

Commit

Permalink
Merge pull request cyberman54#620 from cyberman54/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
cyberman54 authored Jul 29, 2020
2 parents 23974bb + 316cd8d commit 4c2aad8
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 145 deletions.
2 changes: 1 addition & 1 deletion include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ extern configData_t cfg; // current device configuration
extern char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer
extern uint8_t volatile channel; // wifi channel rotation counter
extern uint8_t batt_level; // display value
extern uint16_t volatile macs_total, macs_wifi, macs_ble; // display values
extern uint16_t volatile macs_wifi, macs_ble; // display values
extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC
extern timesource_t timeSource;
extern hw_timer_t *displayIRQ, *matrixDisplayIRQ, *ppsIRQ;
Expand Down
4 changes: 3 additions & 1 deletion include/irqhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define BME_IRQ 0x080
#define MATRIX_DISPLAY_IRQ 0x100
#define PMU_IRQ 0x200
#define MQTT_IRQ 0x400

#include "globals.h"
#include "button.h"
Expand All @@ -20,10 +21,12 @@
#include "bmesensor.h"
#include "power.h"
#include "ledmatrixdisplay.h"
#include "mqttclient.h"

void irqHandler(void *pvParameters);
void mask_user_IRQ();
void unmask_user_IRQ();
void doIRQ(int irq);

#ifdef HAS_DISPLAY
void IRAM_ATTR DisplayIRQ();
Expand All @@ -41,5 +44,4 @@ void IRAM_ATTR ButtonIRQ();
void IRAM_ATTR PMUIRQ();
#endif


#endif
26 changes: 19 additions & 7 deletions include/mqttclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,35 @@

#include "globals.h"
#include "rcommand.h"
#include <MQTT.h>
#include <ETH.h>
#include <PubSubClient.h>

#define MQTT_INTOPIC "paxcounter_in/"
#define MQTT_OUTTOPIC "paxcounter_out/"
#define MQTT_ETHERNET 0 // set to 0 to run on Wifi
#define MQTT_INTOPIC "paxin"
#define MQTT_OUTTOPIC "paxout"
#define MQTT_PORT 1883
#define MQTT_SERVER "broker.hivemq.com"
#define MQTT_RETRYSEC 10 // retry reconnect every 10 seconds
#define MQTT_SERVER "broker.shiftr.io"
//#define MQTT_CLIENTNAME "arduino"
#define MQTT_USER "try"
#define MQTT_PASSWD "try"
#define MQTT_RETRYSEC 20 // retry reconnect every 20 seconds
#define MQTT_KEEPALIVE 10 // keep alive interval in seconds
#define MQTT_TIMEOUT 1000 // timeout for all mqtt commands in milliseconds

#ifndef MQTT_CLIENTNAME
#define MQTT_CLIENTNAME clientId.c_str()
#endif

extern TaskHandle_t mqttTask;
extern PubSubClient mqttClient;

void mqtt_enqueuedata(MessageBuffer_t *message);
void mqtt_queuereset(void);
void mqtt_irq(void);
void mqtt_loop(void);
void mqtt_client_task(void *param);
int mqtt_connect(const char *my_host, const uint16_t my_port);
void mqtt_callback(char *topic, byte *payload, unsigned int length);
void mqtt_callback(MQTTClient *client, char topic[], char payload[],
int length);
void NetworkEvent(WiFiEvent_t event);
esp_err_t mqtt_init(void);

Expand Down
19 changes: 9 additions & 10 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,31 @@ halfile = generic.h

[platformio]
; upload firmware to board with usb cable
default_envs = usb
;default_envs = usb
; upload firmware to a jfrog bintray repository
;default_envs = ota
; use latest versions of libraries
;default_envs = dev
default_envs = dev
description = Paxcounter is a device for metering passenger flows in realtime. It counts how many mobile devices are around.

[common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.9.996
; 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
debug_level = 3
debug_level = 4
extra_scripts = pre:build.py
otakeyfile = ota.conf
lorakeyfile = loraconf.h
lmicconfigfile = lmic_config.h
platform_espressif32 = [email protected].2
platform_espressif32 = [email protected].4
monitor_speed = 115200
upload_speed = 115200 ; set by build.py and taken from hal file
display_library = ; set by build.py and taken from hal file
lib_deps_lora =
MCCI LoRaWAN LMIC [email protected] ; MCCI LMIC by Terrill Moore
lib_deps_display =
;OneBitDisplay@>1.4.0
https://github.com/bitbank2/OneBitDisplay.git
[email protected]
[email protected]
[email protected]
TFT_eSPI@>=2.2.8
Expand All @@ -73,19 +72,19 @@ lib_deps_rgbled =
lib_deps_gps =
1655@>=1.0.2 ; #1655 TinyGPSPlus by Mikal Hart
lib_deps_sensors =
Adafruit Unified Sensor@>=1.1.3
Adafruit Unified Sensor@>=1.1.4
Adafruit BME280 Library@>=2.0.2
Adafruit BMP085 Library@>=1.1.0
BSEC Software [email protected]
https://github.com/ricki-z/SDS011.git
lib_deps_basic =
ArduinoJson@<6
76@>=1.2.4 ; #76 Timezone by Jack Christensen
274@>=2.3.4 ; #274 RTC by Michael Miller
274@>=2.3.5 ; #274 RTC by Michael Miller
SimpleButton
AXP202X_Library@>=1.1.1 ; AXP202 PMU lib by Lewis He
AXP202X_Library@>=1.1.2 ; AXP202 PMU lib by Lewis He
esp32-micro-sdcard
PubSubClient@>=2.8.0
MQTT@>=2.4.7 ; MQTT client maintained by Joel Gaehwiler
lib_deps_all =
${common.lib_deps_basic}
${common.lib_deps_lora}
Expand Down
2 changes: 0 additions & 2 deletions src/cyclic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void doHousekeeping() {
#ifdef HAS_MQTT
ESP_LOGD(TAG, "MQTTloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(mqttTask), eTaskGetState(mqttTask));
mqttClient.loop();
#endif

#if (defined HAS_DCF77 || defined HAS_IF482)
Expand Down Expand Up @@ -152,7 +151,6 @@ uint32_t getFreeRAM() {
void reset_counters() {
#if ((WIFICOUNTER) || (BLECOUNTER))
macs.clear(); // clear all macs container
macs_total = 0; // reset all counters
macs_wifi = 0;
macs_ble = 0;
#ifdef HAS_DISPLAY
Expand Down
3 changes: 3 additions & 0 deletions src/hal/m5fire.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// upload_speed 921600
// board m5stack-fire

// note use of GPIO16/17
// https://www.bjoerns-techblog.de/2019/03/m5stack-fire-eine-uebersicht/

#ifndef _M5FIRE_H
#define _M5FIRE_H

Expand Down
2 changes: 1 addition & 1 deletion src/hal/olimexpoeiso.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdint.h>

// enable only if you want to store a local paxcount table on the device
//#define HAS_SDCARD 2 // this board has a SDMMC card-reader/writer
#define HAS_SDCARD 2 // this board has a SDMMC card-reader/writer

// enable only if you want to send paxcount via ethernet port to mqtt server
#define HAS_MQTT 1 // use MQTT on ethernet interface
Expand Down
4 changes: 2 additions & 2 deletions src/hal/ttgobeam10.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/*
Hardware related definitions for TTGO T-Beam board
for T-Beam versions T22_V10 + T22_V11
for T-Beam version T22_V10 + T22_V11
pinouts taken from https://github.com/lewisxhe/TTGO-T-Beam
/// Button functions: ///
Expand Down Expand Up @@ -61,7 +61,7 @@ Reset -> reset device

/*
// T-Beam V10 has on board power management by AXP192 PMU chip:
// T-Beam V10/V11 has on board power management by AXP192 PMU chip:
//
// DCDC1 0.7-3.5V @ 1200mA -> OLED
// DCDC3 0.7-3.5V @ 700mA -> ESP32 (keep this on!)
Expand Down
49 changes: 17 additions & 32 deletions src/irqhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ void irqHandler(void *pvParameters) {
}
#endif

// MQTT loop due?
#if (HAS_MQTT)
if (InterruptStatus & MQTT_IRQ) {
mqtt_loop();
InterruptStatus &= ~MQTT_IRQ;
}
#endif

// are cyclic tasks due?
if (InterruptStatus & CYCLIC_IRQ) {
doHousekeeping();
Expand All @@ -91,53 +99,30 @@ void irqHandler(void *pvParameters) {
} // for
} // irqHandler()

// esp32 hardware timer triggered interrupt service routines
// timer triggered interrupt service routines
// they notify the irq handler task

#ifdef HAS_DISPLAY
void IRAM_ATTR DisplayIRQ() {
void IRAM_ATTR doIRQ(int irq) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

xTaskNotifyFromISR(irqHandlerTask, DISPLAY_IRQ, eSetBits,
&xHigherPriorityTaskWoken);
xTaskNotifyFromISR(irqHandlerTask, irq, eSetBits, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}

#ifdef HAS_DISPLAY
void IRAM_ATTR DisplayIRQ() { doIRQ(DISPLAY_IRQ); }
#endif

#ifdef HAS_MATRIX_DISPLAY
void IRAM_ATTR MatrixDisplayIRQ() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

xTaskNotifyFromISR(irqHandlerTask, MATRIX_DISPLAY_IRQ, eSetBits,
&xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}
void IRAM_ATTR MatrixDisplayIRQ() { doIRQ(MATRIX_DISPLAY_IRQ); }
#endif

#ifdef HAS_BUTTON
void IRAM_ATTR ButtonIRQ() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

xTaskNotifyFromISR(irqHandlerTask, BUTTON_IRQ, eSetBits,
&xHigherPriorityTaskWoken);

if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}
void IRAM_ATTR ButtonIRQ() { doIRQ(BUTTON_IRQ); }
#endif

#ifdef HAS_PMU
void IRAM_ATTR PMUIRQ() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

xTaskNotifyFromISR(irqHandlerTask, PMU_IRQ, eSetBits,
&xHigherPriorityTaskWoken);

if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}
void IRAM_ATTR PMUIRQ() { doIRQ(PMU_IRQ); }
#endif

void mask_user_IRQ() { xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); }
Expand Down
2 changes: 1 addition & 1 deletion src/loraconf.sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static const u4_t DEVADDR =
0x00000000; // <-- Change this address for every node!

// set additional ABP parameters in loraconf_abp.cpp
void setABPParamaters();
void setABPParameters();

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/loraconf_abp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*********************************************************************/

void setABPParamaters() {
void setABPParameters() {

/** **************************************************************
* ************************************************************* */
Expand Down
4 changes: 3 additions & 1 deletion src/lorawan.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Basic Config

#if (HAS_LORA)
#include "lorawan.h"

Expand Down Expand Up @@ -319,7 +320,7 @@ esp_err_t lora_stack_init(bool do_join) {
memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY));
LMIC_setSession(NETID, DEVADDR, nwkskey, appskey);
// These parameters are defined as macro in loraconf.h
setABPParamaters();
setABPParameters();
#else
// Start join procedure if not already joined,
// lora_setupForNetwork(true) is called by eventhandler when joined
Expand Down Expand Up @@ -581,6 +582,7 @@ const char *getCrName(rps_t rps) {

#if (VERBOSE)
// decode LORAWAN MAC message
// see https://github.com/mcci-catena/arduino-lmic/blob/master/doc/LoRaWAN-at-a-glance.pdf
void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, bool is_down) {

if (!cmdlen)
Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ configData_t cfg; // struct holds current device configuration
char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message
uint8_t volatile channel = 0; // channel rotation counter
uint8_t batt_level = 0; // display value
uint16_t volatile macs_total = 0, macs_wifi = 0,
macs_ble = 0; // globals for display
uint16_t volatile macs_wifi = 0, macs_ble = 0; // globals for display

hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL;

Expand Down
Loading

0 comments on commit 4c2aad8

Please sign in to comment.