new senddata structure

This commit is contained in:
Klaus K Wilting committed 2018-07-14 19:12:20 +02:00
1 parent e6e835e4fc
commit f0cf08bd75
57 files changed
+67 -18098

No files matched your search

-38
View File
@@ -105,44 +105,6 @@ void printKeys(void) {
#endif // VERBOSE
void do_send(osjob_t *j) {
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(cfg.sendcycle * 2),
do_send);
// Check if there is a pending TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
ESP_LOGI(TAG, "LoRa busy, rescheduling");
sprintf(display_lmic, "LORA BUSY");
return;
}
// Prepare payload with counter and, if applicable, gps data
payload.reset();
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
#ifdef HAS_GPS
if ((cfg.gpsmode) && (gps.location.isValid())) {
gps_read();
payload.addGPS(gps_status);
}
#endif
// send payload
LMIC_setTxData2(COUNTERPORT, payload.getBuffer(), payload.getSize(),
(cfg.countermode & 0x02));
ESP_LOGI(TAG, "%d bytes queued to send", payload.getSize());
sprintf(display_lmic, "PACKET QUEUED");
// clear counter if not in cumulative counter mode
if (cfg.countermode != 1) {
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
ESP_LOGI(TAG, "Counter cleared (countermode = %d)", cfg.countermode);
}
} // do_send()
void onEvent(ev_t ev) {
char buff[24] = "";
-1
View File
@@ -2,7 +2,6 @@
#define LORAWAN_H
void onEvent(ev_t ev);
void do_send(osjob_t *j);
void gen_lora_deveui(uint8_t *pdeveui);
void RevBytes(unsigned char *b, size_t c);
void get_hard_deveui(uint8_t *pdeveui);
+9 -5
View File
@@ -652,8 +652,8 @@ void setup() {
}
#endif
// joins network and rescedules sendjob for cyclic transmitting payload
do_send(&sendjob);
// send initial payload to open transfer interfaces
senddata(PAYLOADPORT);
}
/* end Arduino SETUP
@@ -671,6 +671,10 @@ void loop() {
uptimecounter = uptime() / 1000; // counts uptime in seconds (64bit)
// send data every x seconds, x/2 is configured in cfg.sendcycle
if (uptime() % (cfg.sendcycle * 20000) == 0)
senddata(PAYLOADPORT);
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
led_loop();
#endif
@@ -689,9 +693,9 @@ void loop() {
"Memory full, counter cleared (heap low water mark = %d Bytes / "
"free heap = %d bytes)",
esp_get_minimum_free_heap_size(), ESP.getFreeHeap());
do_send(&sendjob); // send count
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
senddata(PAYLOADPORT); // send data before clearing counters
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
}
#ifdef HAS_GPS
+1
View File
@@ -2,6 +2,7 @@
#include "configmanager.h"
#include "lorawan.h"
#include "macsniff.h"
#include "senddata.h"
// program version - note: increment version after modifications to configData_t
// struct!!
+6 -2
View File
@@ -4,6 +4,10 @@
//
// Note: After editing, before "build", use "clean" button in PlatformIO!
//
#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
// Verbose enables serial output
#define VERBOSE 1 // comment out to silence the device, for mute use build option
@@ -35,7 +39,7 @@
#define WIFI_MY_COUNTRY "EU" // select locale for Wifi RF settings
#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec.
// LoRa payload parameters
// LoRa payload default parameters
#define PAYLOAD_ENCODER 2 // select payload encoder: 1=Plain [default], 2=Packed, 3=CayenneLPP
#define SEND_SECS 120 // payload send cycle [seconds/2] -> 240 sec.
#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle
@@ -46,7 +50,7 @@
#define LORASFDEFAULT 9 // 7 ... 12 SF, according to LoRaWAN specs
#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy
#define RCMDPORT 2 // LoRaWAN Port on which device listenes for remote commands
#define COUNTERPORT 1 // LoRaWAN Port on which device sends counts
#define PAYLOADPORT 1 // LoRaWAN Port on which device sends counts
// Default RGB LED luminosity (in %)
#define RGBLUMINOSITY 30 // 30%
+43
View File
@@ -0,0 +1,43 @@
// Basic Config
#include "globals.h"
void senddata(uint8_t port) {
// Prepare payload with counter and, if applicable, gps data
payload.reset();
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
// append GPS data, if present
#ifdef HAS_GPS
if ((cfg.gpsmode) && (gps.location.isValid())) {
gps_read();
payload.addGPS(gps_status);
}
#endif
#ifdef HAS_LORA
// Check if there is a pending TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
ESP_LOGI(TAG, "LoRa busy, rescheduling");
sprintf(display_lmic, "LORA BUSY");
} else {
// send payload via LoRa
LMIC_setTxData2(PAYLOADPORT, payload.getBuffer(), payload.getSize(), (cfg.countermode & 0x02));
ESP_LOGI(TAG, "%d bytes queued to send on LoRa", payload.getSize());
sprintf(display_lmic, "PACKET QUEUED");
}
#endif
#ifdef HAS_SPI
// code for sending payload via SPI to come
ESP_LOGI(TAG, "%d bytes sent on SPI", payload.getSize());
#endif
// clear counter if not in cumulative counter mode
if (cfg.countermode != 1) {
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
ESP_LOGI(TAG, "Counter cleared (countermode = %d)", cfg.countermode);
}
} // senddata
+6
View File
@@ -0,0 +1,6 @@
#ifndef SENDDATA_H
#define SENDDATA_H
void senddata(uint8_t port);
#endif // _SENDDATA_H_