Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 15 additions & 41 deletions aether/aether_c/aether_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,53 +258,18 @@ int AetherInit(AetherConfig const* config) {
auto* wifi_conf =
reinterpret_cast<AeWifiAdapterConf*>(conf);

static ae::IpV4Addr my_static_ip_v4{192, 168, 1, 100};
static ae::IpV4Addr my_gateway_ip_v4{192, 168, 1, 1};
static ae::IpV4Addr my_netmask_ip_v4{255, 255, 255, 0};
static ae::IpV4Addr my_dns1_ip_v4{8, 8, 8, 8};
static ae::IpV4Addr my_dns2_ip_v4{8, 8, 4, 4};
static ae::IpV6Addr my_static_ip_v6{
0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00,
0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34};

static ae::WiFiIP wifi_ip{
{my_static_ip_v4}, // ESP32 static IP
{my_gateway_ip_v4}, // IP Address of your network
// gateway (router)
{my_netmask_ip_v4}, // Subnet mask
{my_dns1_ip_v4}, // Primary DNS (optional)
{my_dns2_ip_v4}, // Secondary DNS (optional)
{my_static_ip_v6} // ESP32 static IP v6
};

static ae::WifiCreds my_wifi{wifi_conf->ssid,
wifi_conf->password};

ae::WiFiAp wifi_ap{my_wifi, wifi_ip};

std::vector<ae::WiFiAp> wifi_ap_vec{wifi_ap};

static ae::WiFiPowerSaveParam wifi_psp{
true,
AE_WIFI_PS_MAX_MODEM, // Power save type
AE_WIFI_PROTOCOL_11B | AE_WIFI_PROTOCOL_11G |
AE_WIFI_PROTOCOL_11N, // Protocol bitmap
3, // Listen interval
500, // Beacon interval
0, // Fix rate
3, // Short retry
3, // Long retry
8 // Power
};
ae::WifiCreds my_wifi{wifi_conf->ssid, wifi_conf->password};
ae::WiFiAp wifi_ap{std::move(my_wifi), std::nullopt};
std::vector<ae::WiFiAp> wifi_ap_vec{std::move(wifi_ap)};

ae::WiFiInit wifi_init{
wifi_ap_vec, // Wi-Fi access points
wifi_psp, // Power save parameters
std::move(wifi_ap_vec), // Wi-Fi access points
{}, // Power save parameters
};

adapters->Add(ae::WifiAdapter::ptr::Create(
context.domain(), context.aether(), context.poller(),
context.dns_resolver(), wifi_init));
context.dns_resolver(), std::move(wifi_init)));
# endif
break;
}
Expand Down Expand Up @@ -394,6 +359,15 @@ void FreeClient(AetherClient* client) {
delete client;
}

int GetClientUid(AetherClient* client, CUid* uid) {
if (!client->client) {
return -1;
}
auto client_uid = client->client->uid();
*uid = CUidFromBytes(client_uid.value.data(), client_uid.value.size());
return 0;
}

void Send(CUid destination, void const* data, size_t size,
ActionStatusCb status_cb, void* user_data) {
assert(default_client);
Expand Down
9 changes: 9 additions & 0 deletions aether/aether_c/aether_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ AetherClient* SelectClient(ClientConfig const* config);
*/
void FreeClient(AetherClient* client);

/**
* \brief Read client's uid.
* This should be called on fully loaded client's only.
* \param client to read uid from.
* \param uid the pointer to read uid to.
* \return if 0, operation success, !0 something get wrong.
*/
int GetClientUid(AetherClient* client, CUid* uid);

/**
* \brief Send a message from selected client to destination client.
* \param client The client to send the message from.
Expand Down
35 changes: 25 additions & 10 deletions examples/capi/oddity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,37 @@

cmake_minimum_required(VERSION 3.16.0)

list(APPEND src_list
main.c
aether_oddity.c)

if(NOT CM_PLATFORM)
project("aether-oddity" VERSION "1.0.0" LANGUAGES C)

add_executable(${PROJECT_NAME} ${src_list})
target_link_libraries(${PROJECT_NAME} PRIVATE aether)
add_executable("aether-tom" aether_tom.c)
target_link_libraries("aether-tom" PRIVATE aether)

add_executable("aether-ground-control" aether_ground_control.c)
target_link_libraries("aether-ground-control" PRIVATE aether)
else()
idf_build_get_property(CM_PLATFORM CM_PLATFORM)
if(CM_PLATFORM STREQUAL "ESP32")
set(SELECTED_ODDITY "" CACHE STRING "The selected oddity example values:[GROUND_CONTROL, TOM]")
set(WIFI_SSID "" CACHE STRING "Wifi ssid")
set(WIFI_PASSWORD "" CACHE STRING "Wifi password")

#ESP32 CMake
idf_component_register(SRCS ${src_list}
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
PRIV_REQUIRES aether)
if (SELECTED_ODDITY STREQUAL "GROUND_CONTROL")
idf_component_register(SRCS aether_ground_control.c
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
PRIV_REQUIRES aether)
else()
set(DEST_UID "" CACHE STRING "Destination uid")

idf_component_register(SRCS aether_tom.c
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
PRIV_REQUIRES aether)
if (NOT DEST_UID STREQUAL "")
target_compile_definitions(${COMPONENT_LIB} PRIVATE "DEST_UID=\"${DEST_UID}\"" )
endif()
endif()
target_compile_definitions(${COMPONENT_LIB} PRIVATE ${WIFI_SSID} "WIFI_SSID=\"${WIFI_SSID}\"" )
target_compile_definitions(${COMPONENT_LIB} PRIVATE ${WIFI_PASSWORD} "WIFI_PASSWORD=\"${WIFI_PASSWORD}\"" )
else()
#Other platforms
message(FATAL_ERROR "Platform ${CM_PLATFORM} is not supported")
Expand Down
131 changes: 131 additions & 0 deletions examples/capi/oddity/aether_ground_control.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright 2026 Aethernet Inc.
*
* 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 <stdio.h>

#ifdef ESP_PLATFORM
# include <freertos/FreeRTOS.h>
# include <esp_log.h>
# include <esp_task_wdt.h>
#endif

extern int AetherGC();

#ifdef ESP_PLATFORM
void app_main() {
esp_task_wdt_config_t config_wdt = {
.timeout_ms = 60000,
.idle_core_mask = 0, // i.e. do not watch any idle task
.trigger_panic = true};

esp_err_t err = esp_task_wdt_reconfigure(&config_wdt);
if (err != 0) {
fprintf(stderr, "Reconfigure WDT is failed!\n");
}

AetherGC();
}
#endif

#if (defined(__linux__) || defined(__unix__) || defined(__APPLE__) || \
defined(__FreeBSD__) || defined(_WIN64) || defined(_WIN32))
int main(int argc, char* argv[]) { return AetherGC(); }
#endif

#include "aether/capi.h"

void PrintUid(CUid const* uid) {
int i = 0;
for (; i < 4; i++) {
printf("%02x", uid->value[i]);
}
printf("-");
for (; i < 6; i++) {
printf("%02x", uid->value[i]);
}
printf("-");
for (; i < 8; i++) {
printf("%02x", uid->value[i]);
}
printf("-");
for (; i < 10; i++) {
printf("%02x", uid->value[i]);
}
printf("-");
for (; i < 16; i++) {
printf("%02x", uid->value[i]);
}
}

#define TEST_UID "3ac93165-3d37-4970-87a6-fa4ee27744e4"
char const* message = "Ground control to Major Tom";

void ClientSelected(AetherClient* client, void* user_data) {
CUid uid;
GetClientUid(client, &uid);
printf(">>> Loaded clieint with uid:");
PrintUid(&uid);
printf("<<<\n");
}

void MessageSentCb(ActionStatus status, void* user_data) { AetherExit(0); }

void MessageReceived(AetherClient* client, CUid sender, void const* data,
size_t size, void* user_data) {
printf(">>> Received message size: %zu test: %s\n", size, (char const*)data);
// send message and wait till it sent
SendStr(sender, message, MessageSentCb, NULL);
}

int AetherGC() {
// This init aether library
// Send a message and wait for response

#ifdef ESP_PLATFORM
AeWifiAdapterConf wifi_adapter_conf = {
.type = AeWifiAdapter,
.ssid = WIFI_SSID,
.password = WIFI_PASSWORD,
};
AdapterBase* adapter_confs = (AdapterBase*)&wifi_adapter_conf;
Adapters adapters = {
.count = 1,
.adapters = &adapter_confs,
};
#endif

ClientConfig client_config = {
.id = "ground control",
.parent_uid = CUidFromString(TEST_UID),
.client_selected_cb = ClientSelected,
.message_received_cb = MessageReceived,
};

AetherConfig aether_config = {
#ifdef ESP_PLATFORM
.adapters = &adapters,
#endif
.default_client = &client_config,
};

AetherInit(&aether_config);

while (AetherExcited() == AE_NOK) {
uint64_t time = AetherUpdate();
AetherWait(time);
}
return AetherEnd();
}
52 changes: 0 additions & 52 deletions examples/capi/oddity/aether_oddity.c

This file was deleted.

Loading
Loading