Skip to content

Commit

Permalink
Merge pull request #200 from cyberman54/development
Browse files Browse the repository at this point in the history
v1.6.62
  • Loading branch information
cyberman54 authored Nov 8, 2018
2 parents cd756af + 8d2aeac commit a51d9f7
Show file tree
Hide file tree
Showing 43 changed files with 541 additions and 428 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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.

Metered counts are transferred to a server via a LoRaWAN network, and/or a local SPI cable interface.
Data is transferred to a server via a LoRaWAN network, and/or a wired SPI slave interface.

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

Expand All @@ -33,15 +33,16 @@ This can all be done with a single small and cheap ESP32 board for less than $20
LoLin32lite + [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora)
- Adafruit ESP32 Feather + LoRa Wing + OLED Wing, #IoT Octopus32 (Octopus + ESP32 Feather)

*SPI only*: (code yet to come)
*SPI only*:

- Pyom: WiPy
- WeMos: LoLin32, LoLin32 Lite, WeMos D32
- Generic ESP32

Depending on board hardware following features are supported:
- LED
- OLED Display
- RGB LED
- LED (power/status)
- OLED Display (detailed status)
- RGB LED (colorized status)
- Button
- Silicon unique ID
- Battery voltage monitoring
Expand Down
25 changes: 11 additions & 14 deletions include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ typedef struct {
uint8_t Message[PAYLOAD_BUFFER_SIZE];
} MessageBuffer_t;

typedef struct {
uint32_t latitude;
uint32_t longitude;
uint8_t satellites;
uint16_t hdop;
uint16_t altitude;
} gpsStatus_t;

// global variables
extern configData_t cfg; // current device configuration
extern char display_line6[], display_line7[]; // screen buffers
Expand All @@ -52,24 +60,17 @@ extern std::array<uint64_t, 0xff> beacons;

extern TaskHandle_t irqHandlerTask, wifiSwitchTask;

#include "led.h"
#include "payload.h"

#ifdef HAS_GPS
#include "gpsread.h"
#endif

#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
#include "led.h"
#endif

#include "payload.h"

#ifdef HAS_LORA
#include "lorawan.h"
#endif

#ifdef HAS_SPI
#include "spisend.h"
#endif

#ifdef HAS_DISPLAY
#include "display.h"
#endif
Expand All @@ -90,8 +91,4 @@ extern TaskHandle_t irqHandlerTask, wifiSwitchTask;
#include "antenna.h"
#endif

void reset_counters(void);
void blink_LED(uint16_t set_color, uint16_t set_blinkduration);
uint64_t uptime();

#endif
8 changes: 0 additions & 8 deletions include/gpsread.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
#include <Wire.h>
#endif

typedef struct {
uint32_t latitude;
uint32_t longitude;
uint8_t satellites;
uint16_t hdop;
uint16_t altitude;
} gpsStatus_t;

extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe
extern gpsStatus_t
gps_status; // Make struct for storing gps data globally available
Expand Down
2 changes: 0 additions & 2 deletions include/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ extern TaskHandle_t ledLoopTask;
void rgb_set_color(uint16_t hue);
void blink_LED(uint16_t set_color, uint16_t set_blinkduration);
void ledLoop(void *parameter);
#if (HAS_LED != NOT_A_PIN)
void switch_LED(uint8_t state);
#endif

#endif
5 changes: 5 additions & 0 deletions include/lorawan.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ void os_getDevEui(u1_t *buf);
void showLoraKeys(void);
void switch_lora(uint8_t sf, uint8_t tx);
void lora_send(osjob_t *job);
void lora_enqueuedata(uint8_t messageType, MessageBuffer_t *message);
void lora_queuereset(void);
void lora_housekeeping(void);

esp_err_t lora_stack_init();

#endif
2 changes: 2 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
#include "ota.h"
#include "irqhandler.h"
#include "led.h"
#include "spislave.h"
#include "lorawan.h"

#endif
5 changes: 3 additions & 2 deletions include/ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#ifdef USE_OTA

#include "globals.h"
#include "update.h"
#include "battery.h"
#include "update.h"
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <BintrayClient.h>
#include <string>
#include <algorithm>

void do_ota_update();
int do_ota_update();
void start_ota_update();
int version_compare(const String v1, const String v2);
void display(const uint8_t row, const std::string status,
Expand Down
4 changes: 0 additions & 4 deletions include/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ class PayloadConvert {
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp, uint32_t mem,
uint8_t reset1, uint8_t reset2);
void addAlarm(int8_t rssi, uint8_t message);
#ifdef HAS_GPS
void addGPS(gpsStatus_t value);
#endif
#ifdef HAS_BUTTON
void addButton(uint8_t value);
#endif

#if PAYLOAD_ENCODER == 1 // format plain

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

#include "senddata.h"
#include "cyclic.h"
#include "configmanager.h"
#include "lorawan.h"
#include "macsniff.h"
Expand Down
4 changes: 4 additions & 0 deletions include/senddata.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef _SENDDATA_H
#define _SENDDATA_H

#include "spislave.h"
#include "lorawan.h"
#include "cyclic.h"

void SendData(uint8_t port);
void sendPayload(void);
void checkSendQueues(void);
Expand Down
34 changes: 0 additions & 34 deletions include/spisend.h

This file was deleted.

36 changes: 36 additions & 0 deletions include/spislave.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
//////////////////////// ESP32-Paxcounter \\\\\\\\\\\\\\\\\\\\\\\\\\
Copyright 2018 Christian Ambach <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
NOTICE:
Parts of the source files in this repository are made available under different
licenses. Refer to LICENSE.txt file in repository for more details.
*/
#ifndef _SPISLAVE_H
#define _SPISLAVE_H

#include "globals.h"

esp_err_t spi_init();

void spi_enqueuedata(uint8_t messageType, MessageBuffer_t *message);
void spi_queuereset();

void spi_housekeeping();

#endif // _SPISLAVE_H
7 changes: 5 additions & 2 deletions include/update.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class UpdateClass {
Call this to check the space needed for the update
Will return false if there is not enough space
*/
bool begin(size_t size=UPDATE_SIZE_UNKNOWN, int command = U_FLASH);
bool begin(size_t size=UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW);

/*
Writes a buffer to the flash and increments the address
Expand Down Expand Up @@ -174,8 +174,11 @@ class UpdateClass {

String _target_md5;
MD5Builder _md5;

int _ledPin;
uint8_t _ledOn;
};

extern UpdateClass Update;

#endif
#endif
5 changes: 3 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng

[common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.6.54
release_version = 1.6.62
; 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 = 0
Expand All @@ -38,7 +38,7 @@ upload_protocol = esptool
;upload_protocol = custom
extra_scripts = pre:build.py
keyfile = ota.conf
platform_espressif32 = espressif32@1.4.0
platform_espressif32 = espressif32@1.5.0
board_build.partitions = min_spiffs.csv
monitor_speed = 115200
lib_deps_all =
Expand All @@ -58,6 +58,7 @@ build_flags =
-w
'-DARDUINO_LMIC_PROJECT_CONFIG_H=../../../src/lmic_config.h'
'-DCORE_DEBUG_LEVEL=${common.debug_level}'
'-DLOG_LOCAL_LEVEL=${common.debug_level}'
'-DBINTRAY_PACKAGE="${PIOENV}"'
'-DPROGVERSION="${common.release_version}"'

Expand Down
21 changes: 15 additions & 6 deletions src/battery.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#ifdef HAS_BATTERY_PROBE

#include "globals.h"

// Local logging tag
static const char TAG[] = "main";

#ifdef HAS_BATTERY_PROBE
esp_adc_cal_characteristics_t *adc_characs =
(esp_adc_cal_characteristics_t *)calloc(
1, sizeof(esp_adc_cal_characteristics_t));

static const adc1_channel_t adc_channel = HAS_BATTERY_PROBE;
static const adc_atten_t atten = ADC_ATTEN_DB_11;
static const adc_unit_t unit = ADC_UNIT_1;
#endif

void calibrate_voltage(void) {
#ifdef HAS_BATTERY_PROBE
// configure ADC
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12));
ESP_ERROR_CHECK(adc1_config_channel_atten(adc_channel, atten));
Expand All @@ -30,9 +31,11 @@ void calibrate_voltage(void) {
} else {
ESP_LOGI(TAG, "ADC characterization based on default reference voltage");
}
#endif
}

uint16_t read_voltage() {
#ifdef HAS_BATTERY_PROBE
// multisample ADC
uint32_t adc_reading = 0;
for (int i = 0; i < NO_OF_SAMPLES; i++) {
Expand All @@ -47,11 +50,17 @@ uint16_t read_voltage() {
#endif
ESP_LOGD(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage);
return voltage;
#else
return 0;
#endif
}

bool batt_sufficient() {
#ifdef HAS_BATTERY_PROBE
uint16_t volts = read_voltage();
return (( volts < 1000 ) || (volts > OTA_MIN_BATT)); // no battery or battery sufficient
}

#endif // HAS_BATTERY_PROBE
return ((volts < 1000) ||
(volts > OTA_MIN_BATT)); // no battery or battery sufficient
#else
return true;
#endif
}
8 changes: 5 additions & 3 deletions src/cyclic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// Basic config
#include "cyclic.h"
#include "rcommand.h"
#include "spislave.h"

// Local logging tag
static const char TAG[] = "main";
Expand All @@ -25,9 +27,9 @@ void doHousekeeping() {
#ifdef HAS_GPS
ESP_LOGD(TAG, "Gpsloop %d bytes left", uxTaskGetStackHighWaterMark(GpsTask));
#endif
#ifdef HAS_SPI
ESP_LOGD(TAG, "Spiloop %d bytes left", uxTaskGetStackHighWaterMark(SpiTask));
#endif

spi_housekeeping();

#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
ESP_LOGD(TAG, "LEDloop %d bytes left", uxTaskGetStackHighWaterMark(ledLoopTask));
#endif
Expand Down
1 change: 0 additions & 1 deletion src/hal/ebox.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Hardware related definitions for ebox ESP32-bit with external connected RFM95 LoRa

#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1

#define HAS_LED (23) // blue LED on board
Expand Down
1 change: 0 additions & 1 deletion src/hal/eboxtube.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Hardware related definitions for ebox ESP32-bit with external connected RFM95 LoRa

#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1

#define HAS_LED (22) // Green LED on board
Expand Down
Loading

0 comments on commit a51d9f7

Please sign in to comment.