I am just curious about the function of thing.handle()
and when should we call it.
The function in the library is:
void handle(unsigned long current_time, bool bytes_available)
{
// handle input
if(bytes_available){
thinger_message message;
synchronized(bool result = read_message(message)==MESSAGE;)
if(result) handle_request_received(message);
}
// handle keep alive (send keep alive to server to prevent disconnection)
if(current_time-last_keep_alive>KEEP_ALIVE_MILLIS){
if(keep_alive_response){
last_keep_alive = current_time;
keep_alive_response = false;
send_keep_alive();
}else{
disconnected();
}
}
// handle streaming resources
if(thinger_resource::get_streaming_counter()>0){
handle_streaming(resources_, current_time);
}
}
bytes_available
seems like to check if there are any new input, so the first part of it should check if we update the inputs on the dashboard.
Then the second part is to check if the device is connected to the system, and update the timer on both the device and the server if yes.
The third part is to stream the output to the dashboard or bucket if any new data are available.
So my assumption is:
- we need to call
thing.handle()
to update the input values inthing["name"] << [](pson& in)
. - we need to call
thing.handle()
at least once per minute to keep the device connecting to the server.
And my question is:
Should I call thing.handle()
before I use thing.write_bucket
to update the values in thing[“name”] >> [](pson& out) before uploading the data, or the data is updated when thing.write_bucket
is called?