Skip to content

Commit

Permalink
Merge pull request #3 from cyberman54/SDS011
Browse files Browse the repository at this point in the history
Sds011
  • Loading branch information
AugustQu authored Feb 19, 2020
2 parents 33e92d0 + 94e1a6d commit 7bd2b31
Show file tree
Hide file tree
Showing 81 changed files with 641 additions and 4,446 deletions.
70 changes: 56 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Tutorial (in german language): https://www.heise.de/select/make/2019/1/1551099236518668

**#36C3 attendees: i am on site (27th - 30th)! You might contact me via twitter @RecumbentTravel**


<img src="img/Paxcounter-title.jpg">
<img src="img/Paxcounter-ttgo.jpg">
Expand All @@ -20,7 +20,7 @@ Paxcounter is a proof-of-concept device for metering passenger flows in realtime

Intention of this project is to do this without intrusion in privacy: You don't need to track people owned devices, if you just want to count them. Therefore, Paxcounter does not persistenly store MAC adresses and does no kind of fingerprinting the scanned devices.

Data is transferred to a server via a LoRaWAN network, and/or a wired SPI slave interface.
Data is transferred to a server via a LoRaWAN network, and/or a wired SPI slave interface. It can also be stored on a local SD-card.

You can build this project battery powered and reach a full day uptime with a single 18650 Li-Ion cell.

Expand All @@ -33,12 +33,15 @@ This can all be done with a single small and cheap ESP32 board for less than $20
*LoRa & SPI*:

- Heltec: LoRa-32 v1 and v2
- TTGO: T1, T2, T3, T-Beam, T-Fox
- TTGO: T1*, T2*, T3*, T-Beam, T-Fox
- Pycom: LoPy, LoPy4, FiPy
- Radioshuttle.de: [ECO Power Board](https://www.radioshuttle.de/esp32-eco-power/esp32-eco-power-board/)
- WeMos: LoLin32 + [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora),
- WeMos: LoLin32 + [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora),
LoLin32lite + [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora)
- Adafruit ESP32 Feather + LoRa Wing + OLED Wing, #IoT Octopus32 (Octopus + ESP32 Feather)
- M5Stack: [Basic Core IoT*](https://m5stack.com/collections/m5-core/products/basic-core-iot-development-kit) + [Lora Module RA-01H](https://m5stack.com/collections/m5-module/products/lora-module-868mhz), [Fire IoT*](https://m5stack.com/collections/m5-core/products/fire-iot-development-kit)

*) supports microSD-card

*SPI only*:

Expand All @@ -60,6 +63,7 @@ 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)

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 @@ -196,6 +200,43 @@ Follow all steps so far for preparing the device, use the packed payload format.
There in the sensor configuration select "TheThingsNetwork" and set Decoding Profil to "LoRa serialization", enter your TTN Application and Device Id. Decoding option has to be
[{"decoder":"latLng"},{"decoder":"uint16","sensor_id":"yoursensorid"}]

# 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 SDCARD_CS (13) // fill in the correct numbers for your board
#define SDCARD_MOSI (15)
#define SDCARD_MISO (2)
#define SDCARD_SCLK (14)

Please choose the correct number for the connection of the reader/writer.

This is an example of a board with SD-card: https://www.aliexpress.com/item/32990008126.html
In this case you take the file src/hal/ttgov21new.h and add the lines given above (numbers given are for this board).

Another approach would be this tiny board: https://www.aliexpress.com/item/32424558182.html (needs 5V).
In this case you choose the correct file for your ESP32-board in the src/hal-directory and add the lines given above to the correct h-file. Please correct the numbers given in the example to the numbers used corresponding to your wiring.

Some hints:
These cheap devices often handle SD-cards up to 32GB, not bigger ones. They can handle files in the old DOS-way, to say the filenames are in the 8.3-format. And they often cannot handle subdirectories.

The software included here writes data in a file named PAXCOUNT.xx, where xx can range from 00 to 99. The software starts with 00, checks to see if such a file already exists and if yes it will continue with the next number (up to 99 - in this case it will return no sd-card). So an existing file will not be overwritten.

The data is written to the card and after 3 write-operations the data is flushed to the disk. So maybe the last 3 minutes of data get lost when you disconnect the PAXCOUNTER from power.

And finally: this is the data written to the disk:

date, time, wifi, bluet
00.00.1970,00:01:09,2,0
00.00.1970,00:02:09,1,0
00.00.1970,00:03:09,2,0

Format of the data is CSV, which can easily imported into LibreOffice, Excel, .....

If you want to change this please look into src/sdcard.cpp and include/sdcard.h.


# Payload format

You can select different payload formats in [paxcounter.conf](src/paxcounter.conf#L12):
Expand Down Expand Up @@ -326,17 +367,17 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.

Example for EU868:

DataRate Configuration Bit/s
0 LoRa: SF12 / 125 kHz 250
1 LoRa: SF11 / 125 kHz 440
2 LoRa: SF10 / 125 kHz 980
3 LoRa: SF9 / 125 kHz 1760
4 LoRa: SF8 / 125 kHz 3125
5 LoRa: SF7 / 125 kHz 5470
6* LoRa: SF7 / 250 kHz 11000
7* FSK: 50 kbps 50000
DataRate Configuration Bit/s
0 LoRa: SF12 / 125 kHz 250
1 LoRa: SF11 / 125 kHz 440
2 LoRa: SF10 / 125 kHz 980
3 LoRa: SF9 / 125 kHz 1760
4 LoRa: SF8 / 125 kHz 3125
5 LoRa: SF7 / 125 kHz 5470
6* LoRa: SF7 / 250 kHz 11000
7* FSK: 50 kbps 50000
8 .. 14 reserved for future use (RFU)
15 ignored (device keeps current setting)
15 ignored (device keeps current setting)

*) not supported by TheThingsNetwork

Expand Down Expand Up @@ -507,3 +548,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
2 changes: 1 addition & 1 deletion include/bmesensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <Wire.h>

#ifdef HAS_BME680
#include "../lib/Bosch-BSEC/src/bsec.h"
#include <bsec.h>
#elif defined HAS_BME280
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Expand Down
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
2 changes: 1 addition & 1 deletion include/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern uint8_t DisplayIsOn, displaybuf[];
void refreshTheDisplay(bool nextPage = false);
void init_display(bool verbose = false);
void shutdown_display(void);
void draw_page(time_t t, uint8_t page);
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_printqr(uint16_t offset_x, uint16_t offset_y, const char *Message);
Expand Down
2 changes: 1 addition & 1 deletion include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <array>
#include <algorithm>
#include "mallocator.h"
#include "../lib/Bosch-BSEC/src/inc/bsec_datatypes.h"
#include <bsec.h>

// sniffing types
#define MAC_SNIFF_WIFI 0
Expand Down
1 change: 1 addition & 0 deletions include/gpsread.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern TaskHandle_t GpsTask;

int gps_init(void);
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);
Expand Down
10 changes: 9 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 Down Expand Up @@ -55,6 +59,10 @@ class PayloadConvert {
void addButton(uint8_t value);
void addSensor(uint8_t[]);
void addTime(time_t value);
void addPM10(float value);
void addPM25(float value);
private:
void addChars( char* string, int len);

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

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

extern PayloadConvert payload;

#endif // _PAYLOAD_H_
#endif // _PAYLOAD_H_
16 changes: 16 additions & 0 deletions include/sdcard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _SDCARD_H
#define _SDCARD_H

#include <globals.h>
#include <stdio.h>

#include <SPI.h>
#include <mySD.h>

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

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

#endif
13 changes: 13 additions & 0 deletions include/sds011read.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _SDS011READ_H
#define _SDS011READ_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);

#endif // _SDS011READ_H
4 changes: 4 additions & 0 deletions include/senddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "display.h"
#endif

#ifdef HAS_SDCARD
#include "sdcard.h"
#endif

extern Ticker sendcycler;

void SendPayload(uint8_t port, sendprio_t prio);
Expand Down
2 changes: 2 additions & 0 deletions include/spislave.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ licenses. Refer to LICENSE.txt file in repository for more details.

esp_err_t spi_init();

extern TaskHandle_t spiTask;

void spi_enqueuedata(MessageBuffer_t *message);
void spi_queuereset();

Expand Down
39 changes: 0 additions & 39 deletions lib/Bosch-BSEC/LICENSE

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion lib/Bosch-BSEC/config/generic_18v_300s_28d/bsec_iaq.csv

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion lib/Bosch-BSEC/config/generic_18v_300s_4d/bsec_iaq.csv

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion lib/Bosch-BSEC/config/generic_18v_3s_28d/bsec_iaq.csv

This file was deleted.

This file was deleted.

This file was deleted.

Binary file removed lib/Bosch-BSEC/config/generic_18v_3s_4d/bsec_iaq.config
Binary file not shown.
Loading

0 comments on commit 7bd2b31

Please sign in to comment.