commit
2fe2c10219
@ -23,10 +23,10 @@ Currently supported IoT boards:
|
|||||||
- TTGOv2 {1}
|
- TTGOv2 {1}
|
||||||
- Pycom LoPy {2}
|
- Pycom LoPy {2}
|
||||||
- Pycom LoPy4 {2}
|
- Pycom LoPy4 {2}
|
||||||
- LoLin32 with [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora) {2}
|
- LoLin32 with [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora) {2}{3}
|
||||||
- LoLin32 Lite with [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora) {2}
|
- LoLin32 Lite with [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora) {2}{3}
|
||||||
|
|
||||||
{1} on board OLED Display supported; {2} on board RGB LED supported
|
{1} on board OLED Display supported; {2} on board RGB LED supported; {3} on board Hardware unique DEVEUI supported
|
||||||
|
|
||||||
Target platform must be selected in [platformio.ini](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/platformio.ini).<br>
|
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.<br>
|
Hardware dependent settings (pinout etc.) are stored in board files in /hal directory.<br>
|
||||||
@ -52,6 +52,8 @@ Use <A HREF="https://platformio.org/">PlatformIO</A> with your preferred IDE for
|
|||||||
|
|
||||||
Before compiling the code, create file loraconf.h in the /src directory from 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. Only OTAA join is supported, not ABP. The DEVEUI will be derived from the device's MAC adress during device startup and is shown as well on the device's display (if it has one) as on the serial console for copying it to your LoRaWAN network server settings. If you enter a DEVEUI in loraconf.h it will be used instead.
|
Before compiling the code, create file loraconf.h in the /src directory from 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. Only OTAA join is supported, not ABP. The DEVEUI will be derived from the device's MAC adress during device startup and is shown as well on the device's display (if it has one) as on the serial console for copying it to your LoRaWAN network server settings. If you enter a DEVEUI in loraconf.h it will be used instead.
|
||||||
|
|
||||||
|
**If Using a board with Microchip 24AA02E64 Unique ID for deveui, it will override the one of loraconf.h**
|
||||||
|
|
||||||
# Uploading
|
# Uploading
|
||||||
|
|
||||||
To upload the code to your ESP32 board this needs to be switched from run to bootloader mode. Boards with USB bridge like Heltec and TTGO usually have an onboard logic which allows soft switching by the upload tool. In PlatformIO this happenes automatically.<p>
|
To upload the code to your ESP32 board this needs to be switched from run to bootloader mode. Boards with USB bridge like Heltec and TTGO usually have an onboard logic which allows soft switching by the upload tool. In PlatformIO this happenes automatically.<p>
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
// Set your DEVEUI here, if you have one. You can leave this untouched,
|
// Set your DEVEUI here, if you have one. You can leave this untouched,
|
||||||
// then the DEVEUI will be generated during runtime from device's MAC adress
|
// then the DEVEUI will be generated during runtime from device's MAC adress
|
||||||
// Note: Use same format as in TTN console (cut & paste, for your convenience)
|
// Note: Use same format as in TTN console (cut & paste, for your convenience)
|
||||||
|
// *** Take care : If Using a board with Microchip 24AA02E64 Uinique ID for deveui, **
|
||||||
|
// *** this DEVEUI will be overwriten by the one contained in the Microchip module ***
|
||||||
static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
// Note: Use msb format for APPEUI as in TTN console (cut & paste, for your convenience)
|
// Note: Use msb format for APPEUI as in TTN console (cut & paste, for your convenience)
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
#include <lmic.h>
|
#include <lmic.h>
|
||||||
#include <hal/hal.h>
|
#include <hal/hal.h>
|
||||||
|
|
||||||
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
|
#include <Wire.h> // Needed for 24AA02E64, does not hurt anything if included and not used
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t mydata[] = "0000";
|
uint8_t mydata[] = "0000";
|
||||||
|
|
||||||
// Local logging Tag
|
// Local logging Tag
|
||||||
@ -46,6 +50,37 @@ void RevBytes(unsigned char* b, size_t c)
|
|||||||
b[c - 1 - i] = t; }
|
b[c - 1 - i] = t; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_hard_deveui(uint8_t *pdeveui) {
|
||||||
|
// read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present
|
||||||
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
|
uint8_t i2c_ret;
|
||||||
|
// Init this just in case, no more to 100KHz
|
||||||
|
Wire.begin(OLED_SDA, OLED_SCL, 100000);
|
||||||
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
|
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
||||||
|
i2c_ret = Wire.endTransmission();
|
||||||
|
// check if device seen on i2c bus
|
||||||
|
if (i2c_ret == 0) {
|
||||||
|
char deveui[32]="";
|
||||||
|
uint8_t data;
|
||||||
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
|
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
||||||
|
Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8);
|
||||||
|
while (Wire.available()) {
|
||||||
|
data = Wire.read();
|
||||||
|
sprintf(deveui+strlen(deveui), "%02X ", data) ;
|
||||||
|
*pdeveui++ = data;
|
||||||
|
}
|
||||||
|
i2c_ret = Wire.endTransmission();
|
||||||
|
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 found, read DEVEUI %s", deveui);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 not found ret=%d", i2c_ret);
|
||||||
|
}
|
||||||
|
// Set back to 400KHz to speed up OLED
|
||||||
|
Wire.setClock(400000);
|
||||||
|
#endif // MCP 24AA02E64
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
|
|
||||||
// Display a key
|
// Display a key
|
||||||
|
@ -47,7 +47,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
|
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
|
||||||
|
|
||||||
addr2int |= (uint64_t) salt << 48; // prepend 16-bit salt to 48-bit MAC
|
addr2int |= (uint64_t) salt << 48; // prepend 16-bit salt to 48-bit MAC
|
||||||
snprintf(macbuf, 21, "%llx", addr2int); // convert unsigned 64-bit salted MAC to 16 digit hex string
|
snprintf(macbuf, sizeof(macbuf), "%llx", addr2int); // convert unsigned 64-bit salted MAC to 16 digit hex string
|
||||||
hashedmac = rokkit(macbuf, 5); // hash MAC string, use 5 chars to fit hash in uint16_t container
|
hashedmac = rokkit(macbuf, 5); // hash MAC string, use 5 chars to fit hash in uint16_t container
|
||||||
newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique
|
newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique
|
||||||
added = newmac.second; // true if hashed MAC is unique in container
|
added = newmac.second; // true if hashed MAC is unique in container
|
||||||
@ -65,7 +65,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (added) { // first time seen this WIFI or BLE MAC
|
if (added) { // first time seen this WIFI or BLE MAC
|
||||||
snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value
|
snprintf(counter, sizeof(counter), "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value
|
||||||
u8x8.draw2x2String(0, 0, counter); // display number on unique macs total Wifi + BLE
|
u8x8.draw2x2String(0, 0, counter); // display number on unique macs total Wifi + BLE
|
||||||
ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> counted #%05i", typebuff, rssi, hashedmac, macs.size());
|
ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> counted #%05i", typebuff, rssi, hashedmac, macs.size());
|
||||||
} else { // already seen WIFI or BLE MAC
|
} else { // already seen WIFI or BLE MAC
|
||||||
|
42
src/main.cpp
42
src/main.cpp
@ -29,7 +29,7 @@ Refer to LICENSE.txt file in repository for more details.
|
|||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
// OLED driver
|
// OLED driver
|
||||||
#include <U8x8lib.h> // includes <wire.h> if needed for other on board i2c components
|
#include <U8x8lib.h>
|
||||||
|
|
||||||
// LMIC-Arduino LoRaWAN Stack
|
// LMIC-Arduino LoRaWAN Stack
|
||||||
#include "loraconf.h"
|
#include "loraconf.h"
|
||||||
@ -85,6 +85,8 @@ void loadConfig(void);
|
|||||||
// defined in lorawan.cpp
|
// defined in lorawan.cpp
|
||||||
void gen_lora_deveui(uint8_t * pdeveui);
|
void gen_lora_deveui(uint8_t * pdeveui);
|
||||||
void RevBytes(unsigned char* b, size_t c);
|
void RevBytes(unsigned char* b, size_t c);
|
||||||
|
void get_hard_deveui(uint8_t *pdeveui);
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
void printKeys(void);
|
void printKeys(void);
|
||||||
@ -103,12 +105,20 @@ void os_getArtEui (u1_t *buf) {
|
|||||||
void os_getDevEui (u1_t* buf) {
|
void os_getDevEui (u1_t* buf) {
|
||||||
int i=0, k=0;
|
int i=0, k=0;
|
||||||
memcpy(buf, DEVEUI, 8); // get fixed DEVEUI from loraconf.h
|
memcpy(buf, DEVEUI, 8); // get fixed DEVEUI from loraconf.h
|
||||||
for (i=0; i<8 ; i++)
|
for (i=0; i<8 ; i++) {
|
||||||
k += buf[i];
|
k += buf[i];
|
||||||
if (k)
|
}
|
||||||
|
if (k) {
|
||||||
RevBytes(buf, 8); // use fixed DEVEUI and swap bytes to LSB format
|
RevBytes(buf, 8); // use fixed DEVEUI and swap bytes to LSB format
|
||||||
else
|
} else {
|
||||||
gen_lora_deveui(buf); // generate DEVEUI from device's MAC
|
gen_lora_deveui(buf); // generate DEVEUI from device's MAC
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get MCP 24AA02E64 hardware DEVEUI (override default settings if found)
|
||||||
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
|
get_hard_deveui(buf);
|
||||||
|
RevBytes(buf, 8); // swap bytes to LSB format
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// LMIC enhanced Pin mapping
|
// LMIC enhanced Pin mapping
|
||||||
@ -461,30 +471,6 @@ void setup() {
|
|||||||
antenna_init();
|
antenna_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present
|
|
||||||
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
|
||||||
uint8_t i2c_ret;
|
|
||||||
// Init this before OLED, we just need to get value then we're done with i2c bus
|
|
||||||
Wire.begin(OLED_SDA, OLED_SDA, 100000);
|
|
||||||
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
|
||||||
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
|
||||||
i2c_ret = Wire.endTransmission();
|
|
||||||
// check if device seen on i2c bus
|
|
||||||
if (i2c_ret == 0) {
|
|
||||||
char deveui[24];
|
|
||||||
uint8_t data;
|
|
||||||
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
|
||||||
while (Wire.available()) {
|
|
||||||
data = Wire.read();
|
|
||||||
sprintf(deveui+strlen(deveui), "%02X ", data) ;
|
|
||||||
}
|
|
||||||
i2c_ret = Wire.endTransmission();
|
|
||||||
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 found, read DEVEUI %s", deveui);
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 not found ret=%d", i2c_ret);
|
|
||||||
}
|
|
||||||
#endif // MCP 24AA02E64
|
|
||||||
|
|
||||||
// initialize display
|
// initialize display
|
||||||
init_display(PROGNAME, PROGVERSION);
|
init_display(PROGNAME, PROGVERSION);
|
||||||
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// program version - note: increment version after modifications to configData_t struct!!
|
// program version - note: increment version after modifications to configData_t struct!!
|
||||||
#define PROGVERSION "1.2.92" // use max 10 chars here!
|
#define PROGVERSION "1.2.93" // use max 10 chars here!
|
||||||
#define PROGNAME "PAXCNT"
|
#define PROGNAME "PAXCNT"
|
||||||
|
|
||||||
// Verbose enables serial output
|
// Verbose enables serial output
|
||||||
|
Loading…
Reference in New Issue
Block a user