Merge branch 'ota-test' into development
This commit is contained in:
19 files changed
+768
-41
No files matched your search
+79
@@ -0,0 +1,79 @@
|
||||
#include "OTA.h"
|
||||
|
||||
const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE);
|
||||
|
||||
bool Wifi_Connected = false;
|
||||
|
||||
esp_err_t event_handler(void *ctx, system_event_t *event) {
|
||||
switch (event->event_id) {
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
ESP_LOGI(TAG, "Event STA_START");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
Wifi_Connected = true;
|
||||
ESP_LOGI(TAG, "Event STA_GOT_IP");
|
||||
// print the local IP address
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
|
||||
ESP_LOGI(TAG, "IP %s", ip4addr_ntoa(&ip_info.ip));
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
Wifi_Connected = false;
|
||||
ESP_LOGI(TAG, "Event STA_DISCONNECTED");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ota_wifi_init(void) {
|
||||
|
||||
tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_STA;
|
||||
|
||||
// initialize the tcp stack
|
||||
// nvs_flash_init();
|
||||
tcpip_adapter_init();
|
||||
tcpip_adapter_set_hostname(tcpip_if, PROGNAME);
|
||||
tcpip_adapter_dhcpc_start(tcpip_if);
|
||||
|
||||
// initialize the wifi event handler
|
||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
|
||||
// switch off monitor more
|
||||
ESP_ERROR_CHECK(
|
||||
esp_wifi_set_promiscuous(false)); // now switch on monitor mode
|
||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(NULL));
|
||||
|
||||
wifi_sta_config_t cfg;
|
||||
strcpy((char *)cfg.ssid, WIFI_SSID);
|
||||
strcpy((char *)cfg.password, WIFI_PASS);
|
||||
cfg.bssid_set = false;
|
||||
|
||||
wifi_config_t sta_cfg;
|
||||
sta_cfg.sta = cfg;
|
||||
|
||||
wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&wifi_cfg));
|
||||
ESP_ERROR_CHECK(
|
||||
esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
}
|
||||
|
||||
void start_ota_update() {
|
||||
ESP_LOGI(TAG, "Stopping Wifi task on core 0");
|
||||
vTaskDelete(WifiLoopTask);
|
||||
|
||||
ESP_LOGI(TAG, "Stopping LORA task on core 1");
|
||||
vTaskDelete(LoraTask);
|
||||
|
||||
ESP_LOGI(TAG, "Connecting to %s", WIFI_SSID);
|
||||
ota_wifi_init();
|
||||
delay(2000);
|
||||
delay(2000);
|
||||
checkFirmwareUpdates();
|
||||
ESP.restart(); // reached if update was not successful
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef OTA_H
|
||||
#define OTA_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "globals.h"
|
||||
#include <BintrayClient.h>
|
||||
#include <WiFi.h>
|
||||
#include "ota.h"
|
||||
#include "SecureOTA.h"
|
||||
|
||||
void start_ota_update();
|
||||
|
||||
#endif // OTA_H
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <Update.h>
|
||||
#include <BintrayClient.h>
|
||||
#include "SecureOTA.h"
|
||||
|
||||
const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE);
|
||||
|
||||
// Connection port (HTTPS)
|
||||
const int port = 443;
|
||||
|
||||
// Connection timeout
|
||||
const uint32_t RESPONSE_TIMEOUT_MS = 5000;
|
||||
|
||||
// Variables to validate firmware content
|
||||
volatile int contentLength = 0;
|
||||
volatile bool isValidContentType = false;
|
||||
|
||||
void checkFirmwareUpdates()
|
||||
{
|
||||
// Fetch the latest firmware version
|
||||
const String latest = bintray.getLatestVersion();
|
||||
if (latest.length() == 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "Could not load info about the latest firmware, so nothing to update. Continue ...");
|
||||
return;
|
||||
}
|
||||
else if (atoi(latest.c_str()) <= VERSION)
|
||||
{
|
||||
//ESP_LOGI(TAG, "The current firmware is up to date. Continue ...");
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "There is a new version of firmware available: v.%s", latest);
|
||||
processOTAUpdate(latest);
|
||||
}
|
||||
|
||||
// A helper function to extract header value from header
|
||||
inline String getHeaderValue(String header, String headerName)
|
||||
{
|
||||
return header.substring(strlen(headerName.c_str()));
|
||||
}
|
||||
|
||||
/**
|
||||
* OTA update processing
|
||||
*/
|
||||
void processOTAUpdate(const String &version)
|
||||
{
|
||||
String firmwarePath = bintray.getBinaryPath(version);
|
||||
if (!firmwarePath.endsWith(".bin"))
|
||||
{
|
||||
ESP_LOGI(TAG, "Unsupported binary format. OTA update cannot be performed!");
|
||||
return;
|
||||
}
|
||||
|
||||
String currentHost = bintray.getStorageHost();
|
||||
String prevHost = currentHost;
|
||||
|
||||
WiFiClientSecure client;
|
||||
client.setCACert(bintray.getCertificate(currentHost));
|
||||
|
||||
if (!client.connect(currentHost.c_str(), port))
|
||||
{
|
||||
ESP_LOGI(TAG, "Cannot connect to %s", currentHost);
|
||||
return;
|
||||
}
|
||||
|
||||
bool redirect = true;
|
||||
while (redirect)
|
||||
{
|
||||
if (currentHost != prevHost)
|
||||
{
|
||||
client.stop();
|
||||
client.setCACert(bintray.getCertificate(currentHost));
|
||||
if (!client.connect(currentHost.c_str(), port))
|
||||
{
|
||||
ESP_LOGI(TAG, "Redirect detected! Cannot connect to %s for some reason!", currentHost);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//ESP_LOGI(TAG, "Requesting: " + firmwarePath);
|
||||
|
||||
client.print(String("GET ") + firmwarePath + " HTTP/1.1\r\n");
|
||||
client.print(String("Host: ") + currentHost + "\r\n");
|
||||
client.print("Cache-Control: no-cache\r\n");
|
||||
client.print("Connection: close\r\n\r\n");
|
||||
|
||||
unsigned long timeout = millis();
|
||||
while (client.available() == 0)
|
||||
{
|
||||
if (millis() - timeout > RESPONSE_TIMEOUT_MS)
|
||||
{
|
||||
ESP_LOGI(TAG, "Client Timeout !");
|
||||
client.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (client.available())
|
||||
{
|
||||
String line = client.readStringUntil('\n');
|
||||
// Check if the line is end of headers by removing space symbol
|
||||
line.trim();
|
||||
// if the the line is empty, this is the end of the headers
|
||||
if (!line.length())
|
||||
{
|
||||
break; // proceed to OTA update
|
||||
}
|
||||
|
||||
// Check allowed HTTP responses
|
||||
if (line.startsWith("HTTP/1.1"))
|
||||
{
|
||||
if (line.indexOf("200") > 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "Got 200 status code from server. Proceeding to firmware flashing");
|
||||
redirect = false;
|
||||
}
|
||||
else if (line.indexOf("302") > 0)
|
||||
{
|
||||
ESP_LOGI(TAG, "Got 302 status code from server. Redirecting to the new address");
|
||||
redirect = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "Could not get a valid firmware url");
|
||||
//Unexptected HTTP response. Retry or skip update?
|
||||
redirect = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Extracting new redirect location
|
||||
if (line.startsWith("Location: "))
|
||||
{
|
||||
String newUrl = getHeaderValue(line, "Location: ");
|
||||
ESP_LOGI(TAG, "Got new url: %s", newUrl);
|
||||
newUrl.remove(0, newUrl.indexOf("//") + 2);
|
||||
currentHost = newUrl.substring(0, newUrl.indexOf('/'));
|
||||
newUrl.remove(newUrl.indexOf(currentHost), currentHost.length());
|
||||
firmwarePath = newUrl;
|
||||
ESP_LOGI(TAG, "firmwarePath: %s", firmwarePath);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Checking headers
|
||||
if (line.startsWith("Content-Length: "))
|
||||
{
|
||||
contentLength = atoi((getHeaderValue(line, "Content-Length: ")).c_str());
|
||||
ESP_LOGI(TAG, "Got %s bytes from server", String(contentLength));
|
||||
}
|
||||
|
||||
if (line.startsWith("Content-Type: "))
|
||||
{
|
||||
String contentType = getHeaderValue(line, "Content-Type: ");
|
||||
ESP_LOGI(TAG, "Got %s payload", contentType);
|
||||
if (contentType == "application/octet-stream")
|
||||
{
|
||||
isValidContentType = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check whether we have everything for OTA update
|
||||
if (contentLength && isValidContentType)
|
||||
{
|
||||
if (Update.begin(contentLength))
|
||||
{
|
||||
ESP_LOGI(TAG, "Starting Over-The-Air update. This may take some time to complete ...");
|
||||
size_t written = Update.writeStream(client);
|
||||
|
||||
if (written == contentLength)
|
||||
{
|
||||
ESP_LOGI(TAG, "Written %s successfully", String(written));
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "Written only %s / %s Retry?", String(written), String(contentLength));
|
||||
// Retry??
|
||||
}
|
||||
|
||||
if (Update.end())
|
||||
{
|
||||
if (Update.isFinished())
|
||||
{
|
||||
ESP_LOGI(TAG, "OTA update has successfully completed. Rebooting ...");
|
||||
ESP.restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "Something went wrong! OTA update hasn't been finished properly.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "An error occurred. Error #: %s", String(Update.getError()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "There isn't enough space to start OTA update");
|
||||
client.flush();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "There was no valid content in the response from the OTA server!");
|
||||
client.flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef SECURE_OTA_H
|
||||
#define SECURE_OTA_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
void checkFirmwareUpdates();
|
||||
void processOTAUpdate(const String &version);
|
||||
|
||||
#endif // SECURE_OTA_H
|
||||
@@ -21,7 +21,6 @@ function Decoder(bytes, port) {
|
||||
return decode(bytes, [uint16, uptime, uint8, uint32], ['voltage', 'uptime', 'cputemp', 'memory']);
|
||||
}
|
||||
|
||||
|
||||
if (port === 3) {
|
||||
// device config data
|
||||
return decode(bytes, [uint8, uint8, uint16, uint8, uint8, uint8, uint8, bitmap], ['lorasf', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags']);
|
||||
@@ -181,6 +180,7 @@ if (typeof module === 'object' && typeof module.exports !== 'undefined') {
|
||||
uint16: uint16,
|
||||
uint32: uint32,
|
||||
uptime: uptime,
|
||||
reset: reset,
|
||||
temperature: temperature,
|
||||
humidity: humidity,
|
||||
latLng: latLng,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// Basic config
|
||||
#include "globals.h"
|
||||
#include "senddata.h"
|
||||
#include "ota.h"
|
||||
|
||||
// Local logging tag
|
||||
static const char TAG[] = "main";
|
||||
@@ -14,6 +15,9 @@ void doHomework() {
|
||||
// update uptime counter
|
||||
uptime();
|
||||
|
||||
if (ota_update)
|
||||
start_ota_update();
|
||||
|
||||
// read battery voltage into global variable
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
batt_voltage = read_voltage();
|
||||
|
||||
+10
-2
@@ -42,7 +42,8 @@ typedef struct {
|
||||
} MessageBuffer_t;
|
||||
|
||||
// global variables
|
||||
extern configData_t cfg; // current device configuration
|
||||
extern configData_t cfg; // current device configuration
|
||||
extern bool ota_update;
|
||||
extern char display_line6[], display_line7[]; // screen buffers
|
||||
extern uint8_t channel; // wifi channel rotation counter
|
||||
extern uint16_t macs_total, macs_wifi, macs_ble, batt_voltage; // display values
|
||||
@@ -51,7 +52,8 @@ extern hw_timer_t *channelSwitch, *sendCycle;
|
||||
extern portMUX_TYPE timerMux;
|
||||
extern volatile int SendCycleTimerIRQ, HomeCycleIRQ, DisplayTimerIRQ,
|
||||
ChannelTimerIRQ, ButtonPressedIRQ;
|
||||
extern QueueHandle_t LoraSendQueue, SPISendQueue;
|
||||
// extern QueueHandle_t LoraSendQueue, SPISendQueue;
|
||||
extern TaskHandle_t WifiLoopTask;
|
||||
|
||||
extern std::array<uint64_t, 0xff>::iterator it;
|
||||
extern std::array<uint64_t, 0xff> beacons;
|
||||
@@ -67,9 +69,15 @@ extern std::array<uint64_t, 0xff> beacons;
|
||||
#include "payload.h"
|
||||
|
||||
#ifdef HAS_LORA
|
||||
extern QueueHandle_t LoraSendQueue;
|
||||
extern TaskHandle_t LoraTask;
|
||||
#include "lorawan.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAS_SPI
|
||||
extern QueueHandle_t SPISendQueue;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_DISPLAY
|
||||
#include "display.h"
|
||||
#endif
|
||||
|
||||
+13
-5
@@ -27,7 +27,8 @@ licenses. Refer to LICENSE.txt file in repository for more details.
|
||||
#include "globals.h"
|
||||
#include "main.h"
|
||||
|
||||
configData_t cfg; // struct holds current device configuration
|
||||
configData_t cfg; // struct holds current device configuration
|
||||
bool ota_update = false; // triggers OTA update
|
||||
char display_line6[16], display_line7[16]; // display buffers
|
||||
uint8_t channel = 0; // channel rotation counter
|
||||
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
||||
@@ -41,9 +42,12 @@ hw_timer_t *channelSwitch = NULL, *displaytimer = NULL, *sendCycle = NULL,
|
||||
volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0,
|
||||
DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
|
||||
|
||||
TaskHandle_t WifiLoopTask = NULL;
|
||||
|
||||
// RTos send queues for payload transmit
|
||||
#ifdef HAS_LORA
|
||||
QueueHandle_t LoraSendQueue;
|
||||
TaskHandle_t LoraTask = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_SPI
|
||||
@@ -67,6 +71,9 @@ static const char TAG[] = "main";
|
||||
|
||||
void setup() {
|
||||
|
||||
// disable the default wifi logging
|
||||
esp_log_level_set("wifi", ESP_LOG_NONE);
|
||||
|
||||
char features[100] = "";
|
||||
|
||||
// disable brownout detection
|
||||
@@ -89,7 +96,8 @@ void setup() {
|
||||
|
||||
// initialize system event handler for wifi task, needed for
|
||||
// wifi_sniffer_init()
|
||||
esp_event_loop_init(NULL, NULL);
|
||||
// esp_event_loop_init(NULL, NULL);
|
||||
//ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
|
||||
// print chip information on startup if in verbose mode
|
||||
#ifdef VERBOSE
|
||||
@@ -269,7 +277,7 @@ void setup() {
|
||||
|
||||
ESP_LOGI(TAG, "Starting Lora task on core 1");
|
||||
xTaskCreatePinnedToCore(lorawan_loop, "loraloop", 2048, (void *)1,
|
||||
(5 | portPRIVILEGE_BIT), NULL, 1);
|
||||
(5 | portPRIVILEGE_BIT), &LoraTask, 1);
|
||||
#endif
|
||||
|
||||
// if device has GPS and it is enabled, start GPS reader task on core 0 with
|
||||
@@ -298,7 +306,7 @@ void setup() {
|
||||
// gets it's seed from RF noise
|
||||
reset_salt(); // get new 16bit for salting hashes
|
||||
xTaskCreatePinnedToCore(wifi_channel_loop, "wifiloop", 2048, (void *)1, 1,
|
||||
NULL, 0);
|
||||
&WifiLoopTask, 0);
|
||||
} // setup()
|
||||
|
||||
/* end Arduino SETUP
|
||||
@@ -330,7 +338,7 @@ void loop() {
|
||||
processSendBuffer();
|
||||
// check send cycle and enqueue payload if cycle is expired
|
||||
sendPayload();
|
||||
// reset watchdog
|
||||
// reset watchdog
|
||||
vTaskDelay(1 / portTICK_PERIOD_MS);
|
||||
|
||||
} // loop()
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
|
||||
// Payload send cycle and encoding
|
||||
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec.
|
||||
#define PAYLOAD_ENCODER 1 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed
|
||||
#define PAYLOAD_ENCODER 2 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed
|
||||
|
||||
// Set this to include BLE counting and vendor filter functions
|
||||
#define VENDORFILTER 1 // comment out if you want to count things, not people
|
||||
|
||||
+9
-4
@@ -54,6 +54,7 @@ void PayloadConvert::addConfig(configData_t value) {
|
||||
|
||||
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||
float cputemp, uint32_t mem) {
|
||||
|
||||
buffer[cursor++] = highByte(voltage);
|
||||
buffer[cursor++] = lowByte(voltage);
|
||||
buffer[cursor++] = (byte)((uptime & 0xFF00000000000000) >> 56);
|
||||
@@ -69,6 +70,8 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||
buffer[cursor++] = (byte)((mem & 0x00FF0000) >> 16);
|
||||
buffer[cursor++] = (byte)((mem & 0x0000FF00) >> 8);
|
||||
buffer[cursor++] = (byte)((mem & 0x000000FF));
|
||||
buffer[cursor++] = (byte)(reset1);
|
||||
buffer[cursor++] = (byte)(reset2);
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
@@ -123,12 +126,14 @@ void PayloadConvert::addConfig(configData_t value) {
|
||||
value.vendorfilter ? true : false, value.gpsmode ? true : false);
|
||||
}
|
||||
|
||||
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||
float cputemp, uint32_t mem) {
|
||||
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp,
|
||||
uint32_t mem, uint8_t reset1, uint8_t reset2) {
|
||||
writeUint16(voltage);
|
||||
writeUptime(uptime);
|
||||
writeUint8((byte)cputemp);
|
||||
writeUint32(mem);
|
||||
writeUint8(reset1);
|
||||
writeUint8(reset2);
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
@@ -241,8 +246,8 @@ void PayloadConvert::addConfig(configData_t value) {
|
||||
buffer[cursor++] = value.adrmode;
|
||||
}
|
||||
|
||||
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||
float celsius, uint32_t mem) {
|
||||
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius,
|
||||
uint32_t mem, uint8_t reset1, uint8_t reset2) {
|
||||
uint16_t temp = celsius * 10;
|
||||
uint16_t volt = voltage / 10;
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
|
||||
+2
-3
@@ -35,7 +35,8 @@ public:
|
||||
uint8_t *getBuffer(void);
|
||||
void addCount(uint16_t value1, uint16_t value2);
|
||||
void addConfig(configData_t value);
|
||||
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp, uint32_t mem);
|
||||
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);
|
||||
@@ -44,7 +45,6 @@ public:
|
||||
void addButton(uint8_t value);
|
||||
#endif
|
||||
|
||||
|
||||
#if PAYLOAD_ENCODER == 1 // format plain
|
||||
|
||||
private:
|
||||
@@ -77,7 +77,6 @@ private:
|
||||
#else
|
||||
#error "No valid payload converter defined"
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
extern PayloadConvert payload;
|
||||
|
||||
+9
-3
@@ -203,7 +203,8 @@ void get_status(uint8_t val[]) {
|
||||
#endif
|
||||
payload.reset();
|
||||
payload.addStatus(voltage, uptime() / 1000, temperatureRead(),
|
||||
ESP.getFreeHeap());
|
||||
ESP.getFreeHeap(), rtc_get_reset_reason(0),
|
||||
rtc_get_reset_reason(1));
|
||||
SendData(STATUSPORT);
|
||||
};
|
||||
|
||||
@@ -219,6 +220,11 @@ void get_gps(uint8_t val[]) {
|
||||
#endif
|
||||
};
|
||||
|
||||
void set_update(uint8_t val[]) {
|
||||
ESP_LOGI(TAG, "Remote command: get firmware update");
|
||||
ota_update = true;
|
||||
};
|
||||
|
||||
// assign previously defined functions to set of numeric remote commands
|
||||
// format: opcode, function, #bytes params,
|
||||
// flag (1 = do make settings persistent / 0 = don't)
|
||||
@@ -233,8 +239,8 @@ cmd_t table[] = {
|
||||
{0x0d, set_vendorfilter, 1, false}, {0x0e, set_blescan, 1, true},
|
||||
{0x0f, set_wifiant, 1, true}, {0x10, set_rgblum, 1, true},
|
||||
{0x11, set_monitor, 1, true}, {0x12, set_beacon, 7, false},
|
||||
{0x80, get_config, 0, false}, {0x81, get_status, 0, false},
|
||||
{0x84, get_gps, 0, false}};
|
||||
{0x20, set_update, 0, false}, {0x80, get_config, 0, false},
|
||||
{0x81, get_status, 0, false}, {0x84, get_gps, 0, false}};
|
||||
|
||||
const uint8_t cmdtablesize =
|
||||
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "configmanager.h"
|
||||
#include "lorawan.h"
|
||||
#include "macsniff.h"
|
||||
#include <rom/rtc.h>
|
||||
|
||||
// table of remote commands and assigned functions
|
||||
typedef struct {
|
||||
|
||||
+2
-1
@@ -6,7 +6,7 @@
|
||||
static const char TAG[] = "wifi";
|
||||
|
||||
static wifi_country_t wifi_country = {WIFI_MY_COUNTRY, WIFI_CHANNEL_MIN,
|
||||
WIFI_CHANNEL_MAX, 0,
|
||||
WIFI_CHANNEL_MAX, 100,
|
||||
WIFI_COUNTRY_POLICY_MANUAL};
|
||||
|
||||
// using IRAM_:ATTR here to speed up callback function
|
||||
@@ -36,6 +36,7 @@ void wifi_sniffer_init(void) {
|
||||
ESP_ERROR_CHECK(
|
||||
esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
|
||||
ESP_ERROR_CHECK(esp_wifi_stop());
|
||||
ESP_ERROR_CHECK(
|
||||
esp_wifi_set_promiscuous_filter(&filter)); // set MAC frame filter
|
||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler));
|
||||
|
||||
Reference in new issue
Block a user