Hi,
I am working on a project to blink RGB LED attached to MKR1000 based on the values received from a
Web Server. Every time the Web Server receives a new input (from other clients, say smartphones), it sends a control command to MKR1000 to Blink the RGB LED with different colors.
The question is will my MKR1000 be a server or client?
For me MKR1000 can be a server, as it is waiting for the client (Web Server in this case), but it is not supposed to provide any service instead to received some data.
The second option is MKR1000 can be a client as well but I don't want it to start communication as the communication is started by the Web Server based on events.
May be I just need to establish communication btw my MKR1000 and the Web Server without considering them as server and client, but what is the right way to do it?
I've done something similar where several Arduinos are clients to a central server, and each Arduino chats with the server bi-directionally using UDP. In this way, the Arduinos don't have to poll the server to see if there are pending commands. The thing I don't like about that is I'd like to know whether certain important messages were received, in both directions, so I have to manually code an acknowledgement protocol. So I'm wondering whether I could replace the ack protocol by opening a persistent TCP connection and monitoring it instead. Haven't done much research down that path though.
As far as I know, the limitation of making an Arduino a server is that the existing libraries only handle one connection at a time (someone correct me if I'm wrong!).
Dear Jameslo,
Thank you for your reply. I guess MQTT provides a better way of communication for the cases similar to me.
Now, I am trying to connect the to Mosquitto broker installed on my laptop with MKR1000 but the client.connect() returns -2 to its state and I am unable to connect to the broker.