Skip to content

Commit

Permalink
Merge pull request #608 from cyberman54/development
Browse files Browse the repository at this point in the history
v1.9.996
  • Loading branch information
cyberman54 authored Jun 6, 2020
2 parents de9f01b + 48cbe53 commit 956ea2f
Show file tree
Hide file tree
Showing 22 changed files with 430 additions and 59 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Depending on board hardware following features are supported:
- IF482 (serial) and DCF77 (gpio) time telegram generator
- 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))
- SD-card (see section SD-card here)
- 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](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/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>
Expand Down Expand Up @@ -207,8 +208,11 @@ There in the sensor configuration select "TheThingsNetwork" and set Decoding Pro
# SD-card
Data can be stored on an SD-card if one is availabe. Simply choose the file in src/hal and add the following lines to your hal-file:

#define HAS_SDCARD 1 // this board has an SD-card-reader/writer
// Pins for SD-card
#define HAS_SDCARD 1 // SD-card-reader/writer, using SPI interface
OR
#define HAS_SDCARD 2 // SD-card-reader/writer, using SDMMC interface

// Pins for SPI interface
#define SDCARD_CS (13) // fill in the correct numbers for your board
#define SDCARD_MOSI (15)
#define SDCARD_MISO (2)
Expand Down
10 changes: 7 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,20 @@
myuploadspeed = mykeys["upload_speed"]
env.Replace(BOARD=myboard)
env.Replace(UPLOAD_SPEED=myuploadspeed)
print('\033[94m' + "Target board: " + myboard + " @ " + myuploadspeed + "bps" + '\033[0m')

# re-set partition table
mypartitiontable = config.get("env", "board_build.partitions")
board = env.BoardConfig(myboard)
board.manifest['build']['partitions'] = mypartitiontable

# display target
print('\033[94m' + "TARGET BOARD: " + myboard + " @ " + myuploadspeed + "bps" + '\033[0m')
print('\033[94m' + "Partition table: " + mypartitiontable + '\033[0m')

# set display library
if "display_library" in mykeys:
mydisplay = mykeys["display_library"]
env.Append(display_library=mydisplay)
print('\033[94m' + "Display library: " + mydisplay + '\033[0m')

# parse ota key file
with open(otakeyfile) as myfile:
for line in myfile:
Expand Down
1 change: 1 addition & 0 deletions include/cyclic.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "senddata.h"
#include "rcommand.h"
#include "spislave.h"
#include "mqttclient.h"
#include "bmesensor.h"
#include "display.h"
#include "sds011read.h"
Expand Down
2 changes: 1 addition & 1 deletion include/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "qrcode.h"

#if (HAS_DISPLAY) == 1
#include <ss_oled.h>
#include <OneBitDisplay.h>
#elif (HAS_DISPLAY) == 2
#include <TFT_eSPI.h>
#endif
Expand Down
26 changes: 26 additions & 0 deletions include/mqttclient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _MQTTCLIENT_H
#define _MQTTCLIENT_H

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

#define MQTT_INTOPIC "paxcounter_in/"
#define MQTT_OUTTOPIC "paxcounter_out/"
#define MQTT_PORT 1883
#define MQTT_SERVER "broker.hivemq.com"
#define MQTT_RETRYSEC 10 // retry reconnect every 10 seconds

extern TaskHandle_t mqttTask;
extern PubSubClient mqttClient;

void mqtt_enqueuedata(MessageBuffer_t *message);
void mqtt_queuereset(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 NetworkEvent(WiFiEvent_t event);
esp_err_t mqtt_init(void);

#endif // _MQTTCLIENT_H
20 changes: 20 additions & 0 deletions include/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
#define BAT_MIN_VOLTAGE 3100 // millivolts
#endif

#ifndef PMU_CHG_CUTOFF
#ifdef HAS_PMU
#define PMU_CHG_CUTOFF AXP202_TARGET_VOL_4_2V
#elif defined HAS_IP5306
#define PMU_CHG_CUTOFF 0
#endif
#endif

#ifndef PMU_CHG_CURRENT
#ifdef HAS_PMU
#define PMU_CHG_CURRENT AXP1XX_CHARGE_CUR_450MA
#elif defined HAS_IP5306
#define PMU_CHG_CURRENT 2
#endif
#endif

typedef uint8_t (*mapFn_t)(uint16_t, uint16_t, uint16_t);

uint16_t read_voltage(void);
Expand All @@ -37,10 +53,14 @@ void AXP192_showstatus(void);
#endif // HAS_PMU

#ifdef HAS_IP5306
void IP5306_init(void);
void printIP5306Stats(void);
uint8_t IP5306_GetPowerSource(void);
uint8_t IP5306_GetBatteryLevel(void);
uint8_t IP5306_GetBatteryFull(void);
void IP5306_SetChargerEnabled(uint8_t v);
void IP5306_SetChargeCutoffVoltage(uint8_t v);
void IP5306_SetEndChargeCurrentDetection(uint8_t v);
#endif

// The following map functions were taken from
Expand Down
36 changes: 32 additions & 4 deletions include/sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,42 @@
#include <globals.h>
#include <stdio.h>
#include <SPI.h>

#ifdef HAS_SDCARD
#if HAS_SDCARD == 1
#include <mySD.h>
#elif HAS_SDCARD == 2
#include <SD_MMC.h>
#else
#error HAS_SDCARD unknown card reader value, must be either 1 or 2
#endif
#endif

#ifdef HAS_SDS011
#include "sds011read.h"
#endif

#ifndef SDCARD_CS
#define SDCARD_CS SS
#endif

#ifndef SDCARD_MOSI
#define SDCARD_MOSI MOSI
#endif

#ifndef SDCARD_MISO
#define SDCARD_MISO MISO
#endif

#ifndef SDCARD_SCLK
#define SDCARD_SCLK SCK
#endif

#define SDCARD_FILE_NAME "paxcount.%02d"
#define SDCARD_FILE_HEADER "date, time, wifi, bluet"
#define SDCARD_FILE_NAME "/paxcount.%02d"
#define SDCARD_FILE_HEADER "date, time, wifi, bluet"

bool sdcard_init( void );
void sdcardWriteData( uint16_t, uint16_t);
bool sdcard_init(void);
void sdcardWriteData(uint16_t, uint16_t);
static void createFile(void);

#endif
1 change: 1 addition & 0 deletions include/senddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _SENDDATA_H

#include "spislave.h"
#include "mqttclient.h"
#include "cyclic.h"
#include "sensor.h"
#include "lorawan.h"
Expand Down
28 changes: 16 additions & 12 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ halfile = generic.h
;halfile = tinypicomatrix.h
;halfile = m5core.h
;halfile = m5fire.h
;halfile = olimexpoeiso.h

[platformio]
; upload firmware to board with usb cable
Expand All @@ -45,51 +46,54 @@ description = Paxcounter is a device for metering passenger flows in realtime. I

[common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.9.991
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
extra_scripts = pre:build.py
otakeyfile = ota.conf
lorakeyfile = loraconf.h
lmicconfigfile = lmic_config.h
platform_espressif32 = [email protected].1
platform_espressif32 = [email protected].2
monitor_speed = 115200
upload_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 =
[email protected] ; fast and small OLED lib by Larry Bank
[email protected]
;OneBitDisplay@>1.4.0
https://github.com/bitbank2/OneBitDisplay.git
[email protected]
[email protected]
lib_deps_matrix_display =
[email protected]
TFT_eSPI@>=2.2.8
lib_deps_ledmatrix =
Ultrathin_LED_Matrix@>=1.0.0
lib_deps_rgbled =
SmartLeds@>=1.2.0
lib_deps_gps =
1655@>=1.0.2 ; #1655 TinyGPSPlus by Mikal Hart
lib_deps_sensors =
Adafruit Unified Sensor@>=1.1.2
Adafruit Unified Sensor@>=1.1.3
Adafruit BME280 Library@>=2.0.2
Adafruit BMP085 Library@>=1.0.1
Adafruit BMP085 Library@>=1.1.0
BSEC Software [email protected]
https://github.com/ricki-z/SDS011.git
lib_deps_basic =
ArduinoJson@^5.13.1
76@>=1.2.4 ; #76 Timezone by Jack Christensen
274@>=2.3.4 ; #274 RTC by Michael Miller
SimpleButton
AXP202X_Library@>=1.1.0 ; AXP202 PMU lib by Lewis He
AXP202X_Library@>=1.1.1 ; AXP202 PMU lib by Lewis He
esp32-micro-sdcard
PubSubClient@>=2.8.0
lib_deps_all =
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_display}
${common.lib_deps_rgbled}
${common.lib_deps_gps}
${common.lib_deps_sensors}
${common.lib_deps_matrix_display}
${common.lib_deps_ledmatrix}
build_flags_basic =
-include "src/hal/${board.halfile}"
-include "src/paxcounter.conf"
Expand All @@ -110,7 +114,7 @@ framework = arduino
board = esp32dev
board_build.partitions = min_spiffs.csv
upload_speed = ${common.upload_speed}
;upload_port = COM5
;upload_port = COM7
platform = ${common.platform_espressif32}
lib_deps = ${common.lib_deps_all}
build_flags = ${common.build_flags_all}
Expand Down
5 changes: 5 additions & 0 deletions src/cyclic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ void doHousekeeping() {
ESP_LOGD(TAG, "spiloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(spiTask), eTaskGetState(spiTask));
#endif
#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)
ESP_LOGD(TAG, "Clockloop %d bytes left | Taskstate = %d",
Expand Down
37 changes: 21 additions & 16 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,29 @@ static int dp_row = 0, dp_col = 0, dp_font = 0;

QRCode qrcode;

#ifdef HAS_DISPLAY
#if (HAS_DISPLAY) == 1
SSOLED ssoled;
OBDISP ssoled;
#elif (HAS_DISPLAY) == 2
TFT_eSPI tft = TFT_eSPI();
#else
#error Unknown display type specified in hal file
#endif
#endif

void dp_setup(int contrast) {

#if (HAS_DISPLAY) == 1 // I2C OLED
int rc = oledInit(&ssoled, OLED_TYPE, OLED_ADDR, MY_DISPLAY_FLIP,
MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA,
MY_DISPLAY_SCL, MY_DISPLAY_RST,
OLED_FREQUENCY); // use standard I2C bus at 400Khz

int rc = obdI2CInit(&ssoled, OLED_TYPE, OLED_ADDR, MY_DISPLAY_FLIP,
MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA,
MY_DISPLAY_SCL, MY_DISPLAY_RST,
OLED_FREQUENCY); // use standard I2C bus at 400Khz
assert(rc != OLED_NOT_FOUND);

// set display buffer
oledSetBackBuffer(&ssoled, displaybuf);
oledSetTextWrap(&ssoled, true);
obdSetBackBuffer(&ssoled, displaybuf);
obdSetTextWrap(&ssoled, true);
dp_font = MY_FONT_NORMAL;

#elif (HAS_DISPLAY) == 2 // SPI TFT
Expand Down Expand Up @@ -466,7 +471,7 @@ void dp_setTextCursor(int x, int y) {

#if (HAS_DISPLAY) == 1
dp_row = y;
oledSetCursor(&ssoled, dp_col, dp_row);
obdSetCursor(&ssoled, dp_col, dp_row);

#elif (HAS_DISPLAY) == 2
switch (dp_font >> 1) {
Expand Down Expand Up @@ -538,8 +543,8 @@ void dp_printf(const char *format, ...) {
}
va_end(arg);
#if (HAS_DISPLAY) == 1
oledWriteString(&ssoled, 0, -1, dp_row, temp, dp_font >> 1, dp_font & 0x01,
false);
obdWriteString(&ssoled, 0, -1, dp_row, temp, dp_font >> 1, dp_font & 0x01,
false);
#elif (HAS_DISPLAY) == 2
tft.printf(temp);
#endif
Expand All @@ -550,7 +555,7 @@ void dp_printf(const char *format, ...) {

void dp_dump(uint8_t *pBuffer) {
#if (HAS_DISPLAY) == 1
oledDumpBuffer(&ssoled, pBuffer);
obdDumpBuffer(&ssoled, pBuffer);
#elif (HAS_DISPLAY) == 2
// probably oled buffer stucture is not suitable for tft -> to be checked
tft.drawBitmap(0, 0, pBuffer, MY_DISPLAY_WIDTH, MY_DISPLAY_HEIGHT,
Expand All @@ -561,23 +566,23 @@ void dp_dump(uint8_t *pBuffer) {
void dp_clear(void) {
dp_setTextCursor(0, 0);
#if (HAS_DISPLAY) == 1
oledFill(&ssoled, 0, 1);
obdFill(&ssoled, 0, 1);
#elif (HAS_DISPLAY) == 2
tft.fillScreen(MY_DISPLAY_BGCOLOR);
#endif
}

void dp_contrast(uint8_t contrast) {
#if (HAS_DISPLAY) == 1
oledSetContrast(&ssoled, contrast);
obdSetContrast(&ssoled, contrast);
#elif (HAS_DISPLAY) == 2
// to do: gamma correction for TFT
#endif
}

void dp_power(uint8_t screenon) {
#if (HAS_DISPLAY) == 1
oledPower(&ssoled, screenon);
obdPower(&ssoled, screenon);
#elif (HAS_DISPLAY) == 2
// to come
#endif
Expand All @@ -590,7 +595,7 @@ void dp_shutdown(void) {
ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0);
else {
cfg.screenon = 0;
oledPower(&ssoled, false);
obdPower(&ssoled, false);
delay(DISPLAYREFRESH_MS / 1000 * 1.1);
I2C_MUTEX_UNLOCK(); // release i2c bus access
}
Expand Down Expand Up @@ -630,7 +635,7 @@ void dp_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
uint8_t bRender) {
#if (HAS_DISPLAY) == 1
for (uint16_t xi = x; xi < x + width; xi++)
oledDrawLine(&ssoled, xi, y, xi, y + height - 1, bRender);
obdDrawLine(&ssoled, xi, y, xi, y + height - 1, 1, bRender);
#elif (HAS_DISPLAY) == 2
tft.fillRect(x, y, width, height, MY_DISPLAY_FGCOLOR);
#endif
Expand Down
1 change: 1 addition & 0 deletions src/hal/generic.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// clang-format off
// upload_speed 115200
// board esp32dev
// display_library lib_deps_oled_display

#ifndef _GENERIC_H
#define _GENERIC_H
Expand Down
Loading

0 comments on commit 956ea2f

Please sign in to comment.