SensESP 3.3.0
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
system_info.cpp
Go to the documentation of this file.
1#include "sensesp.h"
2
3#include "system_info.h"
4
5#include <WiFi.h>
6
7#include "Arduino.h"
8#include "sensesp_app.h"
9
10namespace sensesp {
11
13 // getting sporadic divide by 0 exceptions, no harm in skipping a loop.
14 if (elapsed_millis_ == 0) {
15 return;
16 }
17
18 uint32_t current_tick_count_ = event_loop()->getTickCount();
19 output_ =
20 (current_tick_count_ - last_tick_count_) / (elapsed_millis_ / 1000.);
21
22 last_tick_count_ = current_tick_count_;
24
25 this->notify();
26}
27
28void FreeMem::update() { this->emit(ESP.getFreeHeap()); }
29
30void Uptime::update() { this->emit(static_cast<double>(millis()) / 1000.); }
31
33 // Query the active network provisioner so this sensor works for both
34 // WiFi and (future) non-WiFi transports. Defensively null-check the
35 // app singleton: IPAddrDev::update() can run on any event-loop tick,
36 // including before setup() has finished wiring the provisioner.
37 auto app = SensESPApp::get();
38 if (!app) {
39 this->emit(String("0.0.0.0"));
40 return;
41 }
42 auto provisioner = app->get_network_provisioner();
43 if (provisioner) {
44 this->emit(provisioner->local_ip().toString());
45 } else {
46 this->emit(String("0.0.0.0"));
47 }
48}
49
50// WiFiSignal is intentionally still WiFi-specific by name and behaviour.
51// Builder code that calls enable_wifi_signal_sensor() on a non-WiFi
52// deployment will still get this sensor, but it will report 0 since
53// there is no WiFi association. The user is responsible for not enabling
54// it on non-WiFi-only devices.
55void WiFiSignal::update() { this->emit(WiFi.RSSI()); }
56
57} // namespace sensesp
static std::shared_ptr< SensESPApp > get()
Get the singleton instance of the SensESPApp.
Definition sensesp_app.h:54
uint32_t last_tick_count_
Definition system_info.h:61
elapsedMillis elapsed_millis_
Definition system_info.h:62
void emit(const uint32_t &new_value)
std::shared_ptr< reactesp::EventLoop > event_loop()
Definition sensesp.cpp:9