Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Schedule display
#11
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

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;
    }
}
Reply
#12
(07-29-2023, 07:38 PM)iliaslamprou Wrote: 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

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;
    }
}

Thanks a lot, but on Apple Store there is a old version 0.5.44, where i download a new versione for IOS?
Reply
#13
Thanks a lot, but on Apple Store there is a old version 0.5.44, where i download a new versione for IOS?
Reply
#14
Hi,
the iOS version has been uploaded to the AppStore today.
It needs 1 or 2 days until it will be available for the users.

The MacOS version will be delayded.
Reply
#15
i hope that MacOS version will be available sap because i use it often
Thanks a lot.
Reply
#16
Hi iliaslamprou,
i tried a new version 0.6 and it work, but i possible to use more than 1 schedule widget on the same project?.
I tried with 2 widget with variable called scheduleA and scheduleB, but both not working.
My suspect is that only 1 schedule widget for project with variable called schedule, wright?

Thanks
Reply
#17
Hi, 
you can send unlimited schedules.

You have to make some additions to the arduino code like the code below

Code:
//---- Enter all the Tags here. You have to use the same Tags on Virtuino variables
  const char* pin0_tag= "schedule";         // tag for digital input
  String scheduleHolder="";
  unsigned long lastMillis = 0;

  String char* pin1_tag = "schedule2";
  String scheduleHolder2="";

//===================================================== sendPinStatus
void sendPinsStatus(){
  sendValue(pin0_tag,scheduleHolder);    // if you want send the schedule to VirtuinoIoT when the board is
  sendValue(pin1_tag,scheduleHolder2);
connected
  // add more here...
  }

//===================================================== onValueReceived
  void onValueReceived(String tag, String value){
    Serial.println("Received: tag="+tag+ "  value="+value);
 
    if (tag== pin0_tag) {                   
      Serial.println("Schedule received");
      scheduleHolder = value;
    }
    else if (tag== pin1_tag){
      Serial.println("Schedule2 received");
      scheduleHolder2= value;
    }
    }


// call the getscheduleState with the String parameter"mySchedule"

boolean getscheduleState(byte clockDoW, byte clockHour, byte clockMinute, byte clockSecond, String mySchedule){
  boolean returnedState=false;
  JSONVar myObject = JSON.parse(mySchedule);
//........

}


On Virtuino IoT app use a Variable with the tag "schedule" to store the second schedule
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)