Skip to content

Commit

Permalink
1.25 maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
klausahrenberg committed May 17, 2022
1 parent c83078a commit 381a1f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions WAdapter/WDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ const char* DEVICE_TYPE_THERMOSTAT = "Thermostat";
const char* DEVICE_TYPE_TEXT_DISPLAY = "TextDisplay";
const char* DEVICE_TYPE_MULTI_LEVEL_SENSOR = "MultiLevelSensor";
const char* DEVICE_TYPE_MULTI_LEVEL_SWITCH = "MultiLevelSwitch";
const char* DEVICE_TYPE_RADIO = "Radio";

class WNetwork;

class WDevice {
public:

WDevice(WNetwork* network, const char* id, const char* name, const char* type) {
WDevice(WNetwork* network, const char* id, const char* name, const char* type, const char* alternativeType = nullptr) {
this->network = network;
this->id = id;
this->name = name;
this->type = type;
this->alternativeType = alternativeType;
this->visibility = ALL;
this->lastStateNotify = 0;
this->stateNotifyInterval = 300000;
Expand Down Expand Up @@ -106,6 +108,9 @@ class WDevice {
//type
json->beginArray("@type");
json->string(getType());
if (alternativeType != nullptr) {
json->string(alternativeType);
}
json->endArray();
//properties
json->beginObject("properties");
Expand Down Expand Up @@ -179,7 +184,7 @@ class WDevice {
}

WDevice* next = nullptr;
//WebSocketsServer* webSocket;
AsyncWebSocket* webSocket = nullptr;
WProperty* firstProperty = nullptr;
WProperty* lastProperty = nullptr;
WPin* firstPin = nullptr;
Expand All @@ -196,6 +201,7 @@ class WDevice {
const char* id;
const char* name;
const char* type;
const char* alternativeType;

void onPropertyChange() {
this->lastStateNotify = 0;
Expand Down
22 changes: 22 additions & 0 deletions WAdapter/WNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ class WNetwork {
return this->idx->c_str();
}

const char* getHostName() {
return this->hostname;
}

const char* getSsid() {
return this->ssid->c_str();
}
Expand Down Expand Up @@ -1450,9 +1454,27 @@ class WNetwork {
webServer->on(propertiesBase.c_str(), HTTP_GET, std::bind(&WNetwork::sendDeviceValues, this, std::placeholders::_1, device));
webServer->on(deviceBase.c_str(), HTTP_GET, std::bind(&WNetwork::sendDeviceStructure, this, std::placeholders::_1, device));
device->bindWebServerCalls(webServer);

// Initiate the websocket instance
AsyncWebSocket *ws = new AsyncWebSocket("/things/" + String(device->getId()));
device->webSocket = ws;
ws->onEvent(std::bind(
&WNetwork::handleWS, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4,
std::placeholders::_5, std::placeholders::_6, device));
this->webServer->addHandler(ws);
}



}

void handleWS(AsyncWebSocket *server, AsyncWebSocketClient *client,
AwsEventType type, void *arg, const uint8_t *rawData,
size_t len, WDevice *device) {
wlog->notice(F("WebSocket: %s"), rawData);
}

WDevice* getDeviceById(const char* deviceId) {
WDevice *device = this->firstDevice;
while (device != nullptr) {
Expand Down

0 comments on commit 381a1f4

Please sign in to comment.