ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
openthread.h
Go to the documentation of this file.
1#pragma once
3#ifdef USE_OPENTHREAD
4
8
9#include <openthread/thread.h>
10
11#include <optional>
12#include <vector>
13
14namespace esphome {
15namespace openthread {
16
17class InstanceLock;
18
20 public:
23 void setup() override;
24 bool teardown() override;
25 float get_setup_priority() const override { return setup_priority::WIFI; }
26
27 bool is_connected();
29 std::optional<otIp6Address> get_omr_address();
30 void ot_main();
31
32 protected:
33 std::optional<otIp6Address> get_omr_address_(InstanceLock &lock);
34 bool teardown_started_{false};
35 bool teardown_complete_{false};
36};
37
38extern OpenThreadComponent *global_openthread_component; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
39
41 public:
43 // This has to run after the mdns component or else no services are available to advertise
44 float get_setup_priority() const override { return this->mdns_->get_setup_priority() - 1.0; }
45 void setup() override;
46
47 protected:
49 std::vector<esphome::mdns::MDNSService> mdns_services_;
50 std::vector<std::unique_ptr<uint8_t[]>> memory_pool_;
51 void *pool_alloc_(size_t size);
52};
53
55 public:
56 static std::optional<InstanceLock> try_acquire(int delay);
57 static InstanceLock acquire();
59
60 // Returns the global openthread instance guarded by this lock
61 otInstance *get_instance();
62
63 private:
64 // Use a private constructor in order to force thehandling
65 // of acquisition failure
66 InstanceLock() {}
67};
68
69} // namespace openthread
70} // namespace esphome
71#endif
float get_setup_priority() const override
static std::optional< InstanceLock > try_acquire(int delay)
std::optional< otIp6Address > get_omr_address_(InstanceLock &lock)
std::optional< otIp6Address > get_omr_address()
float get_setup_priority() const override
Definition openthread.h:25
std::vector< std::unique_ptr< uint8_t[]> > memory_pool_
Definition openthread.h:50
void set_mdns(esphome::mdns::MDNSComponent *mdns)
std::vector< esphome::mdns::MDNSService > mdns_services_
Definition openthread.h:49
float get_setup_priority() const override
Definition openthread.h:44
esphome::mdns::MDNSComponent * mdns_
Definition openthread.h:48
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:144
OpenThreadComponent * global_openthread_component
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:29