Skip to content

Commit

Permalink
Added chat example
Browse files Browse the repository at this point in the history
  • Loading branch information
amirna2 committed Dec 28, 2024
1 parent c958f48 commit 0bf0653
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 736 deletions.
62 changes: 1 addition & 61 deletions examples/CaptivePortal/CaptivePortal.ino
Original file line number Diff line number Diff line change
@@ -1,81 +1,21 @@
#include "chat.h"
#include "device_info.h"
#include "portal_html.h"
#include <Arduino.h>
#include <RadioMesh.h>

void RxCallback(const RadioMeshPacket* packet, int err);
bool setupAccessPoint();
void handleWifiConfig(void* client, const std::vector<byte>&);
void handleProvision(void* client, const std::vector<byte>&);
void handleFirmware(void* client, const std::vector<byte>&);
void handleMessage(void* client, const std::vector<byte>&);

IDevice* device = nullptr;
IWifiAccessPoint* wifiAP = nullptr;
bool setupOk = false;

// Simple message handler
void handleMessage(void* client, const std::vector<byte>& data)
{
loginfo_ln("Handling Message!");
// device->getCaptivePortal()->sendToClients("status", data);
auto wsClient = static_cast<AsyncWebSocketClient*>(client);
std::string msg(data.begin(), data.end());
device->getCaptivePortal()->sendToClient(wsClient->id(), "status", msg);
}

// Handler for WiFi configuration
void handleWifiConfig(void* client, const std::vector<byte>& data)
{
// Parse JSON and update WiFi settings
// Store in flash/EEPROM
loginfo_ln("Handling WiFi config!");
device->getCaptivePortal()->sendToClients("status", "WiFi configuration updated");
}

// Handler for device provisioning
void handleProvision(void* client, const std::vector<byte>& data)
{
// Parse JSON and provision device
// Update mesh network settings
loginfo_ln("Handling device provision!");
device->getCaptivePortal()->sendToClients("status", "Device provisioned");
}

// Handler for firmware update
void handleFirmware(void* client, const std::vector<byte>& data)
{
// Handle firmware update
// Verify and flash new firmware
loginfo_ln("Handling firmware update!");
device->getCaptivePortal()->sendToClients("status", "Firmware updated");
}

// Portal params with constructor
CaptivePortalParams portalParams{
"RadioMesh Portal", SIMPLE_PORTAL_HTML, 80, 53, {PortalEventHandler{"message", handleMessage}}};

/*
CaptivePortalParams portalParams{"RadioMesh Portal",
PORTAL_HTML,
80,
53,
{{"wifi_config", handleWifiConfig},
{"provision", handleProvision},
{"firmware", handleFirmware}}};
*/

void RxCallback(const RadioMeshPacket* packet, int err)
{
if (err != RM_E_NONE || packet == nullptr) {
logerr_ln("RX Error: %d", err);
return;
}

// Forward mesh packet data to portal
if (device && device->getCaptivePortal()) {
device->getCaptivePortal()->sendToClients("status", packet->packetData);
}
}

bool setupAccessPoint()
Expand Down
Loading

0 comments on commit 0bf0653

Please sign in to comment.