diff --git a/spejsiot/SpejsNode.cpp b/spejsiot/SpejsNode.cpp index 6a899a3..8e7dbf4 100644 --- a/spejsiot/SpejsNode.cpp +++ b/spejsiot/SpejsNode.cpp @@ -22,10 +22,7 @@ void SpejsNode::init() { WifiStation.enable(true); WifiStation.config(WIFI_SSID, WIFI_PWD); - WifiStation.waitConnection( - ConnectionDelegate(&SpejsNode::onConnected, this), 20, *[] { - Serial.println("Connection failed"); - }); + WifiEvents.onStationGotIP(StationGotIPDelegate(&SpejsNode::gotIP, this)); registerEndpoint("$implementation", new ImplementationEndpoint()); @@ -92,6 +89,10 @@ void SpejsNode::httpIndex(HttpRequest &request, HttpResponse &response) /* * Successful network connection handler */ +void SpejsNode::gotIP(IPAddress ip, IPAddress netmask, IPAddress gateway) { + onConnected(); +} + void SpejsNode::onConnected() { Serial.println("Connection successful"); @@ -144,7 +145,7 @@ void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response) String value = req.substring(req.indexOf("/") + 1); if(key.length() == 0 || value.length() == 0 || !endpoints.contains(key)) { - response.badRequest(); + response.code = 400; } else { EndpointResult result = endpoints[key]->onValue(key, value); JsonObjectStream* stream = new JsonObjectStream(); diff --git a/spejsiot/SpejsNode.h b/spejsiot/SpejsNode.h index 3c6eb1e..51d7c82 100644 --- a/spejsiot/SpejsNode.h +++ b/spejsiot/SpejsNode.h @@ -46,6 +46,7 @@ public: deviceType(_deviceType) {}; void onConnected(); + void gotIP(IPAddress ip, IPAddress netmask, IPAddress gateway); void init();