Skip to content

Commit

Permalink
Merge pull request #569 from cyberman54/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
cyberman54 authored Mar 20, 2020
2 parents d457511 + 0800bef commit 4c5721b
Show file tree
Hide file tree
Showing 30 changed files with 565 additions and 238 deletions.
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Depending on board hardware following features are supported:
- Silicon unique ID
- Battery voltage monitoring
- GPS (Generic serial NMEA, or Quectel L76 I2C)
- Environmental sensor (Bosch BMP180/BME280/BME680 I2C)
- Environmental sensors (Bosch BMP180/BME280/BME680 I2C; SDS011 serial)
- Real Time Clock (Maxim DS3231 I2C)
- IF482 (serial) and DCF77 (gpio) time telegram generator
- Switch external power / battery
Expand All @@ -82,25 +82,28 @@ By default bluetooth sniffing is disabled (#define *BLECOUNTER* 0 in paxcounter.

# Preparing

Before compiling the code,
Compile time configuration is spread across several files. Before compiling the code, edit or create the following files:

- **edit platformio.ini** and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections boards.
## platformio.ini
Edit `platformio.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections boards.

- **edit src/paxcounter.conf** and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use.
## src/paxcounter.conf
Edit `src/paxcounter.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use.

- **edit src/lmic_config.h** and tailor settings in this file according to your country and device hardware. Please take care of national regulations when selecting the frequency band for LoRaWAN.
If your device has a **real time clock** it can be updated bei either LoRaWAN network or GPS time, according to settings *TIME_SYNC_INTERVAL* and *TIME_SYNC_LORAWAN* in `paxcounter.conf`.

- **create file loraconf.h in your local /src directory** using the template [loraconf.sample.h](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/loraconf.sample.h) and populate it with your personal APPEUI und APPKEY for the LoRaWAN network. If you're using popular <A HREF="https://thethingsnetwork.org">TheThingsNetwork</A> you can copy&paste the keys from TTN console or output of ttnctl.
## src/lmic_config.h
Edit `src/lmic_config.h` and tailor settings in this file according to your country and device hardware. Please take care of national regulations when selecting the frequency band for LoRaWAN.

- **create file ota.conf in your local /src directory** using the template [ota.sample.conf](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/ota.sample.conf) and enter your WIFI network&key. These settings are used for downloading updates. If you want to push own OTA updates you need a <A HREF="https://bintray.com/JFrog">Bintray account</A>. Enter your Bintray user account data in ota.conf. If you don't need wireless firmware updates just rename ota.sample.conf to ota.conf.
## src/loraconf.h
Create file `src/loraconf.h` using the template [src/loraconf.sample.h](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/loraconf.sample.h) and modify it, to use your personal values.
To join the network and activate your paxcounter, you have to configure either the preferred OTAA method or the ABP method. You should use OTAA, whenever possible. To understand the differences of the two methods, [this article](https://www.thethingsnetwork.org/docs/devices/registration.html) may be useful.

To join the network only method OTAA is supported, not ABP. The DEVEUI for OTAA will be derived from the device's MAC adress during device startup and is shown on the device's display (if it has one). It is also printed on the serial console for copying it, if you set *verbose 1* in paxcounter.conf and *debug_level 3* in platformio.ini.
To configure OTAA, leave `#define LORA_ABP` deactivated (commented). To use ABP, activate (uncomment) `#define LORA_ABP` in the file `src/loraconf.h`.
The file `src/loraconf.h.sample` contains more information about the values to provide.

If your device has a fixed DEVEUI enter this in your local loraconf.h file. During compile time this DEVEUI will be grabbed from loraconf.h and inserted in the code.

If your device has silicon **Unique ID** which is stored in serial EEPROM Microchip 24AA02E64 you don't need to change anything. The Unique ID will be read during startup and DEVEUI will be generated from it, overriding settings in loraconf.h.

If your device has a **real time clock** it can be updated bei either LoRaWAN network or GPS time, according to settings *TIME_SYNC_INTERVAL* and *TIME_SYNC_LORAWAN* in paxcounter.conf.
## src/ota.conf
Create file `src/ota.conf` using the template [src/ota.sample.conf](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/ota.sample.conf) and enter your WIFI network&key. These settings are used for downloading updates. If you want to push own OTA updates you need a <A HREF="https://bintray.com/JFrog">Bintray account</A>. Enter your Bintray user account data in ota.conf. If you don't need wireless firmware updates just rename ota.sample.conf to ota.conf.

# Building

Expand Down Expand Up @@ -167,7 +170,7 @@ by pressing the button of the device.

# Sensors and Peripherals

You can add up to 3 user defined sensors. Insert sensor's payload scheme in [*sensor.cpp*](src/sensor.cpp). Bosch BMP180 / BME280 / BME680 environment sensors are supported. Enable flag *lib_deps_sensors* for your board in [*platformio.ini*](src/platformio.ini) and configure BME in board's hal file before build. If you need Bosch's proprietary BSEC libraray (e.g. to get indoor air quality value from BME680) further enable *build_flags_sensors*, which comes on the price of reduced RAM and increased build size. RTC DS3231, generic serial NMEA GPS, I2C LoPy GPS are supported, and to be configured in board's hal file. See [*generic.h*](src/hal/generic.h) for all options and for proper configuration of BME280/BME680.
You can add up to 3 user defined sensors. Insert sensor's payload scheme in [*sensor.cpp*](src/sensor.cpp). Bosch BMP180 / BME280 / BME680 environment sensors are supported. Enable flag *lib_deps_sensors* for your board in [*platformio.ini*](src/platformio.ini) and configure BME in board's hal file before build. If you need Bosch's proprietary BSEC libraray (e.g. to get indoor air quality value from BME680) further enable *build_flags_sensors*, which comes on the price of reduced RAM and increased build size. Furthermore, SDS011, RTC DS3231, generic serial NMEA GPS, I2C LoPy GPS are supported, and to be configured in board's hal file. See [*generic.h*](src/hal/generic.h) for all options and for proper configuration of BME280/BME680.

Output of user sensor data can be switched by user remote control command 0x14 sent to Port 2.

Expand Down Expand Up @@ -548,4 +551,4 @@ Thanks to
- [terrillmoore](https://github.com/mcci-catena) for maintaining the LMIC for arduino LoRaWAN stack
- [sbamueller](https://github.com/sbamueller) for writing the tutorial in Make Magazine
- [Stefan](https://github.com/nerdyscout) for paxcounter opensensebox integration
- [August Quint](https://github.com/AugustQu) for adding SD card data logger support
- [August Quint](https://github.com/AugustQu) for adding SD card data logger and SDS011 support
9 changes: 9 additions & 0 deletions include/cyclic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
#include "display.h"
#endif

#if (HAS_SDS011)
#include "sds011read.h"
#endif

#if (HAS_SDCARD)
#include "sdcard.h"
#endif


extern Ticker housekeeper;

void housekeeping(void);
Expand Down
26 changes: 26 additions & 0 deletions include/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,41 @@

#include "cyclic.h"
#include "qrcode.h"
#define DISPLAY_PAGES (7) // number of paxcounter display pages

// settings for oled display library
#define USE_BACKBUFFER 1
#define MY_OLED OLED_128x64
#ifdef MY_OLED_ADDR
#define OLED_ADDR MY_OLED_ADDR
#else
#define OLED_ADDR -1
#endif
#define OLED_INVERT 0
#define USE_HW_I2C 1

#ifndef DISPLAY_FLIP
#define DISPLAY_FLIP 0
#endif

// settings for qr code generator
#define QR_VERSION 3 // 29 x 29px
#define QR_SCALEFACTOR 2 // 29 -> 58x < 64px

// settings for curve plotter
#define DISPLAY_WIDTH 128 // Width in pixels of OLED-display, must be 32X
#define DISPLAY_HEIGHT 64 // Height in pixels of OLED-display, must be 64X

extern uint8_t DisplayIsOn, displaybuf[];

void setup_display(int contrast = 0);
void refreshTheDisplay(bool nextPage = false);
void init_display(bool verbose = false);
void shutdown_display(void);
void draw_page(time_t t, bool nextpage);
void dp_printf(uint16_t x, uint16_t y, uint8_t font, uint8_t inv,
const char *format, ...);
void dp_dump(uint8_t *pBuffer);
void dp_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message);
void oledfillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
uint8_t bRender);
Expand Down
5 changes: 5 additions & 0 deletions include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ typedef struct {
float gas; // raw gas sensor signal
} bmeStatus_t;

typedef struct {
float pm10;
float pm25;
} sdsStatus_t;

extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs;
extern std::array<uint64_t, 0xff>::iterator it;
extern std::array<uint64_t, 0xff> beacons;
Expand Down
4 changes: 2 additions & 2 deletions include/gpsread.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int gps_config();
bool gps_hasfix();
void gps_storelocation(gpsStatus_t *gps_store);
void gps_loop(void *pvParameters);
time_t fetch_gpsTime(uint16_t *msec);
time_t fetch_gpsTime(void);
time_t get_gpstime(uint16_t *msec);
time_t get_gpstime(void);

#endif
11 changes: 10 additions & 1 deletion include/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "paxcounter.conf"

#if (HAS_SDS011)
#include "sds011read.h"
#endif

// MyDevices CayenneLPP 1.0 channels for Synamic sensor payload format
// all payload goes out on LoRa FPort 1
#if (PAYLOAD_ENCODER == 3)
Expand All @@ -19,6 +23,8 @@
#define LPP_HUMIDITY_CHANNEL 29
#define LPP_BAROMETER_CHANNEL 30
#define LPP_AIR_CHANNEL 31
#define LPP_PARTMATTER10_CHANNEL 32 // particular matter for PM 10
#define LPP_PARTMATTER25_CHANNEL 33 // particular matter for PM 2.5

// MyDevices CayenneLPP 2.0 types for Packed Sensor Payload, not using channels,
// but different FPorts
Expand Down Expand Up @@ -55,6 +61,9 @@ class PayloadConvert {
void addButton(uint8_t value);
void addSensor(uint8_t[]);
void addTime(time_t value);
void addSDS(sdsStatus_t value);
private:
void addChars( char* string, int len);

#if (PAYLOAD_ENCODER == 1) // format plain

Expand Down Expand Up @@ -95,4 +104,4 @@ class PayloadConvert {

extern PayloadConvert payload;

#endif // _PAYLOAD_H_
#endif // _PAYLOAD_H_
4 changes: 2 additions & 2 deletions include/sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define SDCARD_FILE_NAME "paxcount.%02d"
#define SDCARD_FILE_HEADER "date, time, wifi, bluet"

bool sdcardInit( void );
bool sdcard_init( void );
void sdcardWriteData( uint16_t, uint16_t);

#endif
#endif
15 changes: 15 additions & 0 deletions include/sds011read.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef _SDS011READ_H
#define _SDS011READ_H

#include "globals.h"
#include <SDS011.h>

#define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25"

bool sds011_init();
void sds011_loop();
void sds011_sleep(void);
void sds011_wakeup(void);
void sds011_store(sdsStatus_t *sds_store);

#endif // _SDS011READ_H
4 changes: 2 additions & 2 deletions include/timesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ enum timesync_t {
};

void timesync_init(void);
void timesync_sendReq(void);
void timesync_storeReq(uint32_t timestamp, timesync_t timestamp_type);
void timesync_request(void);
void timesync_store(uint32_t timestamp, timesync_t timestamp_type);
void IRAM_ATTR timesync_processReq(void *taskparameter);
void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag);

Expand Down
9 changes: 5 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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.95
release_version = 1.9.98
; 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
Expand All @@ -59,20 +59,21 @@ upload_speed = 115200
lib_deps_lora =
MCCI LoRaWAN LMIC library@>=3.1.0 ; MCCI LMIC by Terrill Moore
lib_deps_display =
ss_oled@3.3.1 ; simple and small OLED lib by Larry Bank
BitBang_I2C@1.3.0
ss_oled@4.1.0 ; simple and small OLED lib by Larry Bank
BitBang_I2C@2.0.1
QRCode@>=0.0.1
lib_deps_matrix_display =
Ultrathin_LED_Matrix@>=1.0.0
lib_deps_rgbled =
SmartLeds@>=1.1.6
SmartLeds@>=1.2.0
lib_deps_gps =
1655@>=1.0.2 ; #1655 TinyGPSPlus by Mikal Hart
lib_deps_sensors =
Adafruit Unified Sensor@>=1.1.1
Adafruit BME280 Library@>=2.0.0
Adafruit BMP085 Library@>=1.0.1
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
Expand Down
18 changes: 16 additions & 2 deletions src/cyclic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ static const char TAG[] = __FILE__;

Ticker housekeeper;

#if (HAS_SDS011)
extern boolean isSDS011Active;
#endif

void housekeeping() {
xTaskNotifyFromISR(irqHandlerTask, CYCLIC_IRQ, eSetBits, NULL);
}
Expand All @@ -18,7 +22,6 @@ void doHousekeeping() {

// update uptime counter
uptime();

// check if update mode trigger switch was set
if (RTC_runmode == RUNMODE_UPDATE) {
// check battery status if we can before doing ota
Expand Down Expand Up @@ -112,6 +115,17 @@ void doHousekeeping() {
}
#endif

#if (HAS_SDS011)
if ( isSDS011Active ) {
ESP_LOGD(TAG, "SDS011: go to sleep");
sds011_loop();
}
else {
ESP_LOGD(TAG, "SDS011: wakeup");
sds011_wakeup();
}
#endif

} // doHousekeeping()

// uptime counter 64bit to prevent millis() rollover after 49 days
Expand Down Expand Up @@ -143,4 +157,4 @@ void reset_counters() {
#endif

#endif
}
}
Loading

0 comments on commit 4c5721b

Please sign in to comment.