07-29-2023, 07:38 PM
Hi,
you can download the new "Schedule" example from the same link:
https://virtuino.com/downloads/virtuino_...xample.zip
The changes concern only the functions SendValue and webSocketEvent
You have to replace them with the following.
The new functions support the library ArduinoJSON that it is included in this sketch.
This example is supported by Virtuino IoT version 0.6.0 or higher. It will be available at July 31 2023
you can download the new "Schedule" example from the same link:
https://virtuino.com/downloads/virtuino_...xample.zip
The changes concern only the functions SendValue and webSocketEvent
You have to replace them with the following.
The new functions support the library ArduinoJSON that it is included in this sketch.
This example is supported by Virtuino IoT version 0.6.0 or higher. It will be available at July 31 2023
Code:
bool sendValue(const char* tag, String value){
JSONVar myObject;
myObject[tag] = value;
String jsonString = JSON.stringify(myObject);
Serial.println("Send: "+jsonString);
return webSocket.broadcastTXT(jsonString);
}
Code:
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
switch(type) {
case WStype_DISCONNECTED:
Serial.printf("[%u] Disconnected!\n", num);
break;
case WStype_CONNECTED:{
IPAddress ip = webSocket.remoteIP(num);
Serial.printf("[%u] New client connected - IP: %d.%d.%d.%d \n", num, ip[0], ip[1], ip[2], ip[3]);
sendPinsStatus(); // send the initial pin and variable values to the connected clients
break;
}
case WStype_TEXT: // a new message received
Serial.println("--- a new message received ---");
Serial.println((char*) payload);
JSONVar myObject = JSON.parse((char*) payload);
if (JSON.typeof(myObject) == "undefined"){
Serial.println("Parsing incoming Json data failed!");
return;
}
JSONVar keys = myObject.keys();
for (int i = 0; i < keys.length(); i++) {
JSONVar value = myObject[keys[i]];
onValueReceived((const char*)keys[i],(const char*)value);
}
break;
}
}