mirror of
https://github.com/airgradienthq/arduino.git
synced 2026-06-12 12:11:17 +02:00
Run satellites if enabled
This commit is contained in:
@@ -27,6 +27,7 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
|
||||
|
||||
*/
|
||||
#include "AgConfigure.h"
|
||||
#include "AgSatellites.h"
|
||||
#include "AgSchedule.h"
|
||||
#include "AgStateMachine.h"
|
||||
#include "AgValue.h"
|
||||
@@ -99,6 +100,7 @@ static TaskHandle_t mqttTask = NULL;
|
||||
static Configuration configuration(Serial);
|
||||
static Measurements measurements(configuration);
|
||||
static AirGradient *ag;
|
||||
static AgSatellites *satellites = nullptr;
|
||||
static OledDisplay oledDisplay(configuration, measurements, Serial);
|
||||
static StateMachine stateMachine(oledDisplay, Serial, measurements, configuration);
|
||||
static WifiConnector wifiConnector(oledDisplay, Serial, stateMachine, configuration);
|
||||
@@ -210,6 +212,12 @@ void setup() {
|
||||
localServer.setAirGraident(ag);
|
||||
measurements.setAirGradient(ag);
|
||||
|
||||
if (configuration.isSatellitesEnabled()) {
|
||||
satellites = new AgSatellites(measurements, configuration);
|
||||
measurements.setSatellites(satellites);
|
||||
Serial.println("Satellites enabled on boot");
|
||||
}
|
||||
|
||||
/** Init sensor */
|
||||
boardInit();
|
||||
setMeasurementMaxPeriod();
|
||||
@@ -348,6 +356,11 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
/* Run satellite BLE scanning */
|
||||
if (satellites != nullptr) {
|
||||
satellites->run();
|
||||
}
|
||||
|
||||
/* Run measurement schedule */
|
||||
printMeasurementsSchedule.run();
|
||||
|
||||
@@ -1142,6 +1155,15 @@ static void configUpdateHandle() {
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.isSatellitesChanged() && configuration.isSatellitesEnabled()) {
|
||||
if (satellites == nullptr) {
|
||||
// Initialized if satellites enabled on run time
|
||||
satellites = new AgSatellites(measurements, configuration);
|
||||
measurements.setSatellites(satellites);
|
||||
Serial.println("Satellites enabled on runtime");
|
||||
}
|
||||
}
|
||||
|
||||
// Update display and led bar notification based on updated configuration
|
||||
updateDisplayAndLedBar();
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ JSON_PROP_DEF(corrections);
|
||||
JSON_PROP_DEF(atmp);
|
||||
JSON_PROP_DEF(rhum);
|
||||
JSON_PROP_DEF(extendedPmMeasures);
|
||||
JSON_PROP_DEF(satellites);
|
||||
|
||||
#define jprop_model_default ""
|
||||
#define jprop_country_default "TH"
|
||||
|
||||
@@ -44,9 +44,10 @@ bool AgSatellites::run() {
|
||||
|
||||
// Create and set scan callbacks
|
||||
_scanCallbacks = new ScanCallbacks(this);
|
||||
_pScan->setScanCallbacks(_scanCallbacks, false);
|
||||
_pScan->setScanCallbacks(_scanCallbacks, true);
|
||||
|
||||
// Configure scan parameters
|
||||
// TODO: Might need to adjust for reliablity coex wifi
|
||||
_pScan->setInterval(100); // Scan interval in ms
|
||||
_pScan->setWindow(99); // Scan window in ms
|
||||
_pScan->setActiveScan(true); // Active scan for scan response data
|
||||
@@ -94,6 +95,8 @@ void AgSatellites::processAdvertisedDevice(const NimBLEAdvertisedDevice *device)
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.printf("Found satellites: %s\n", macAddress.c_str());
|
||||
|
||||
// Get advertising payload
|
||||
const std::vector<uint8_t> &payload = device->getPayload();
|
||||
if (payload.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user