I am attempting to use some type of Boolean or another simple way of finding out when:
My device connects to the network,
and 2. either when it connects to thinger.io or when it sends my output variable to my data bucket.
Context:
I am using the Arduino MKR GSM 1400 with the thing.handle(), and am attempting to notify the person, that starts the device, with a piezo speaker that is also hooked up to the device. If it connects, and also when it connects to thinger.io, it would use a short buzz each, and if it doesn’t do one of those instances in a certain amount of time, it would send a special long buzz.
I found this while searching the forum
class ClientListener : public ThingerMKRGSM{
public:
ClientListener(const char* user, const char* device, const char* device_credential) :
ThingerMKRGSM(user, device, device_credential){}
protected:
virtual void thinger_state_listener(THINGER_STATE state){
// call current implementation (debug)
ThingerMKRGSM::thinger_state_listener(state);
switch(state){
case NETWORK_CONNECTING:
break;
case NETWORK_CONNECTED:
break;
case NETWORK_CONNECT_ERROR:
break;
case SOCKET_CONNECTING:
break;
case SOCKET_CONNECTED:
break;
case SOCKET_CONNECTION_ERROR:
break;
case SOCKET_DISCONNECTED:
break;
case SOCKET_TIMEOUT:
break;
case THINGER_AUTHENTICATING:
break;
case THINGER_AUTHENTICATED:
break;
case THINGER_AUTH_FAILED:
break;
case THINGER_STOP_REQUEST:
//pulse???
break;
}
}
};
By using this instead of ThingerMKRGSM thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
Would you think this is what I am looking for? With initiating my piezo under NETWORK_CONNECTED, and THINGER_AUTHENTICATED, and using millis() in other spots to check if it hasnt connected yet?
I apologize for my wording, as I am not much of a coder (as can easily be seen)
Please when pasting code, select all and push the “</>” button, it helps us to read your code easy.
On other hand I would recommend the buzzer flags when it cannot achieve something (network or socket connecction, or thinger auth), why? because it will be stuck in that step, so it will give a clue where is the issue or where to start checking.
And of course will add an indicator when it achieves the connecction, to say that everything is ok.
Why I recommend this? because the steps between the connection could be really fast, since it tries to connect the network until it connects successfully to thinger, so I think it makes no sense to try to give an auditive indicator that achieved something that took milliseconds…
The indicator to refer that the data has been uploaded you can put into the “thing” definition (if the device is pooled by the cloud, and or writes the value) , or in the main code, into the write call loop (if the device writes the value).
I understand that you are not a coder, so if you dont understand something, I’m really sorry for you…
Just kidding lol, ask until you understand it, this is easy and you show a good practice that is to read and try to solve instead to wait that someone solves your issue, it helps a lot, to investigate and read previous experiences from thirds in forums.
I attempted to edit the post to preformat the code, to make it easier for anyone else to read it, but I guess I need to drink some coffee and try when I am awake, as I couldn’t seem to fix it.
Thank you for your reply. I will incorporate the code above and try your way of when when to flag, as it does make sense to me.
By the way, can you or someone give me a quick layman’s definition of what the socket is? If I am reading it correctly, after you connect to the network, the socket is used to actually be able to send and receive data across the network. Just want to make sure that is correct.