Arduino IOT Shield acts as Arduino Shield via 1Sheeld

Buy 1Sheeld

 

Turn your smartphone into a MQTT client for your Arduino boards. It opens a lot of internet connected applications to your arduino boards, and let you update & get data through your preferred cloud (Broker).

 

*Currently supported by IOS application only.

 

This shield is one of the special shields. Special shields allows your Arduino board to use some capabilities your smartphone can do, like playing music, taking a picture, getting notifications, accessing the clock data and using the touch screen for various functions. Learn more from the special shields tutorial.

MQTT easily allows you to publish/subscribe to topics over your favorite broker.

Adding #define CUSTOM_SETTINGS along with #define INCLUDE_IOT_SHIELD is a key that will let you unlock iot shield only among all shields, preventing 1Sheeld library from eating your memory especially for UNO board.

Notes

-New to MQTT please check HiveMq’s (MQTT Essentials) series.
-Works with MQTT versions (3.0.0-3.1.1-5.0).
-Supports 1 broker connection.
-Max (1024 messages X 1024 bytes for each message) are queued when internet is lost.
-Check this link for public brokers.
-Using a persistent session requires a unique client ID, but don’t worry we hold your back ! as we already assigned your device’s IMEI as your default client ID. You can check your IMEI from your phone’s settings.
-Only the hostname is required as parameter in case you used connect(void).
-Set all your parameters before calling connect(void) method, otherwise any missing parameters will lead to connection error.You may also use 1 line connect method that takes certain parameters to initiate connection without using setters.
-Default parameters values already set by the application:
Port: 1883.
Client ID: IMEI of your smartphone.
Clean session: true.
Keep Alive: 60 seconds.
Auto Reconnect: true.
SSL connection: false.

bool isConnected(void)

Check if IOT shield is connected to broker.

 

SYNTAX
IOT.isConnected();

 

RETURN
Boolean Yes ‘1’ or No ‘0’.

 

PARAMETERS
None.

 

USAGE
bool isBrokerConnected = IOT.isConnected();

 

void setHost(const char *)

-Set your host’s (broker) name.
-Invoke setHost method before connect(void), otherwise no connection will be initiated.

 

SYNTAX
IOT.setHost(hostName);

 

RETURN
None.

 

PARAMETERS
const char array holding your host name.

 

USAGE
IOT.setHost("test.mosquitto.org");

 

void setHost(String)

-Set your host’s (broker) name.
-Invoke setHost method before connect(void), otherwise no connection will be initiated.

 

SYNTAX
IOT.setHost(hostName);

 

RETURN
None.

 

PARAMETERS
String object holding your host name.

 

USAGE
String hostName = "test.mosquitto.org"; 
IOT.setHost(hostName);

 

void setPort(unsigned int)

-Set broker’s port.
-If you are using SSL connection make sure to set the right port for the secured connection.
-Invoke setPort method before connect(void) to set your port before connecting, or you can use the other connect methods that takes the port number as parameter.
-You may not have to use this method if the port value you gonna assign is 1883, as it’s already set by default in the app.

 

SYNTAX
IOT.setPort(portNumber);

 

RETURN
None.

 

PARAMETERS
unsigned integer holding the port value.

 

USAGE
IOT.setPort(27700);

 

void setClientID(const char *)

-Set your connected client ID to certain value.
-Client ID value is very important and should be unique if used with a persistent session(cleanSession = false).
-Invoke setClientID before any connect methods to set your own unique ID and to erase the default (IMEI) ID set by the app.

 

SYNTAX
IOT.setClientID(clientId);

 

RETURN
None.

 

PARAMETERS
const char array holding your unique client ID.

 

USAGE
IOT.setClientID("B2F52388-99F3);

 

void setClientID(String)

-Set your connected client ID to certain value.
-Client ID value is very important and should be unique if used with a persistent session(cleanSession = false).
-Invoke setClientID before any connect methods to set your own unique ID and to erase the default (IMEI) ID set by the app.

 

SYNTAX
IOT.setClientID(clientId);

 

RETURN
None.

 

PARAMETERS
String object holding your unique client ID.

 

USAGE
String clientID = "B2F52388-99F3";
IOT.setClientID(clientID);

 

void setLastWillAndTestament(const char *,const char *,byte=0,bool=false)

-Set your last will for a connected session.
-Last will is important if another remote devices are interested to know if your device is disconnected from broker.
-It’s very important to assign a unique topic&payload for your client so remote devices would know which device is disconnected.
-Invoke setLastWillAndTestament before any connect methods.

 

SYNTAX
IOT.setLastWillAndTestament(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-Constant char array holding topic.
-Constant char array holding your unique payload (preferred client ID).
-Byte holding last will QOS (quality of service).(default = 0)
-Boolean holding last will retain.(default = false)

 

USAGE
IOT.setLastWillAndTestament("MyDevice/Disconnected","B2F52388-99F3 is disconnected",QOS_1,true);

 

void setLastWillAndTestament(String,String,  byte=0,bool=false)

-Set your last will for a connected session.
-Last will is important if another remote devices are interested to know if your device is disconnected from broker.
-It’s very important to assign a unique topic&payload for your client so remote devices would know which device is disconnected.
-Invoke setLastWillAndTestament before any connect methods.

 

SYNTAX
IOT.setLastWillAndTestament(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-String object holding topic.
-String object holding your unique payload (preferred client ID).
-Byte holding last will QOS (quality of service).(default = 0)
-Boolean holding last will retain.(default = false)

 

USAGE
String topic = "MyDevice/Disconnected";
String payload = "B2F52388-99F3 is disconnected";
IOT.setLastWillAndTestament(topic,payload,QOS_1,true);

 

void setCleanSession(bool)

-Setting clean session to true informs the broker to totally clean your session, and that your client is not interested to any lost data once disconnected.
-Setting clean session to false requires a unique client ID to be assigned.
-Clean session is true by default, but if you want to have a persistent session please invoke setCleanSession(false) before any connect methods.

 

SYNTAX
IOT.setCleanSession(true/false);

 

RETURN
None.

 

PARAMETERS
Boolean holding Yes ‘true’ or No ‘false’ to set your clean session.

 

USAGE
IOT.setCleanSession(true);

 

void setKeepAlive(unsigned int)

-Keep alive is the time the broker regularly check and ask if your client is still connected or not, if there’s no response the broker will call your session dead and will inform the remote devices that you were disconnected (for a persistent session).
-Keep alive is 60 secs by default,but if you want to change the interval invoke keepAlive(newInterval) before any connect methods.

 

SYNTAX
IOT.setKeepAlive(keepAliveValue);

 

RETURN
None.

 

PARAMETERS
Unsigned integer holding your keep alive value in seconds.

 

USAGE
IOT.setKeepAlive(60);

 

void setCredentials(const char *,const char *)

-Set your username and password (used if your broker needs authentication before establishing the connection).
-Invoke setCredentials before any connect method or you may use the connect method that takes the username and password as parameters.

 

SYNTAX
IOT.setCredentials(username,password);

 

RETURN
None.

 

PARAMETERS
-Constant char array holding your username.
-Constant char array holding your password.

 

USAGE
IOT.setCredentials("testingUser","012345");

 

void setCredentials(String,String)

-Set your username and password (used if your broker needs authentication before establishing the connection).
-Invoke setCredentials before any connect method or you may use the connect method that takes the username and password as parameters.

 

SYNTAX
IOT.setCredentials(username,password);

 

RETURN
None.

 

PARAMETERS
-String object holding your username.
-String object holding your password.

 

USAGE
String username = "testingUser";
String password = "012345";
IOT.setCredentials(username ,password);

 

void setAutoReconnect(bool)

-Set this method to true will auto reconnect when your client disconnects from broker.
-Auto reconnect is true by default, but if you want to disable this feature, invoke setAutoReconnect(false) before any connect methods.

 

SYNTAX
IOT.setAutoReconnect(true/false);

 

RETURN
None.

 

PARAMETERS
Boolean holding Yes ‘true’ or No ‘False’.

 

USAGE
IOT.setAutoReconnect(true);

 

void setSecureConnection(bool)

-Assures that the upcoming connection should be secured using SSL connection.
-Secure connection is false by default, but if you want to enable a secured connection invoke setSecureConnection before any connect methods or you may use the connect method that already sets the secure connection as parameter.

 

SYNTAX
IOT.setSecureConnection(true/false);

 

RETURN
None.

 

PARAMETERS
Boolean holding Yes ‘true’ or No ‘False’.

 

USAGE
IOT.setSecureConnection(true);

 

void connect(void)

-Connect to already set host (broker) name.
-Set your public host before invoking this method or no connection will be initiated.

 

SYNTAX
IOT.connect();

 

RETURN
None.

 

PARAMETERS
None.

 

USAGE
IOT.setHost("test.mosquitto.org");
IOT.connect();

 

void connect(const char *)

Connects to a broker given its host name.

 

SYNTAX
IOT.connect(hostname);

 

RETURN
None.

 

PARAMETERS
Const char array holding host name.

 

USAGE
IOT.connect("test.mosquitto.org");

 

void connect(String)

Connects to a broker given its host name.

 

SYNTAX
IOT.connect(hostname);

 

RETURN
None.

 

PARAMETERS
String object holding host name.

 

USAGE
String hostName = "test.mosquitto.org";
IOT.connect(hostName);

 

void connect(const char *,unsigned int)

Connects to a broker given its host name and port number.

 

SYNTAX
IOT.connect(hostname,portNumber);

 

RETURN
None.

 

PARAMETERS
-Const char array holding host name.
-Unsigned integer holding port number.

 

USAGE
IOT.connect("test.mosquitto.org",1883);

 

void connect(String,unsigned int)

Connects to a broker given its host name and port number.

 

SYNTAX
IOT.connect(hostname,portNumber);

 

RETURN
None.

 

PARAMETERS
-String object holding host name.
-Unsigned integer holding port number.

 

USAGE
String hostName = "test.mosquitto.org";
IOT.connect(hostName,1883);

 

void connect(const char *,unsigned int,bool)

Connects securely to a broker using SSL connection given its host name and port number.

 

SYNTAX
IOT.connect(hostname,portNumber);

 

RETURN
None.

 

PARAMETERS
-Const char array holding host name.
-Unsigned integer holding port number.
-Boolean holding Yes ‘true’ or No ‘false’ to activate secured connection.

 

USAGE
IOT.connect("test.mosquitto.org",1883,true);

 

void connect(String,unsigned int,bool)

Connects securely to a broker using SSL connection given its host name and port number.

 

SYNTAX
IOT.connect(hostname,portNumber);

 

RETURN
None.

 

PARAMETERS
-String object holding host name.
-Unsigned integer holding port number.
-Boolean holding Yes ‘true’ or No ‘false’ to activate secured connection.

 

USAGE
String hostName = "test.mosquitto.org";
IOT.connect(hostName,1883,true);

 

void connect(const char *,const char *,const char *,unsigned int)

Connect with an account credentials given hostname and port number.

 

SYNTAX
IOT.connect(hostname,username,password,portNumber);

 

RETURN
None.

 

PARAMETERS
-Const char array holding host name.
-Const char array holding username.
-Const char array holding password.
-Unsigned integer holding port number.

 

USAGE
IOT.connect("test.mosquitto.org","testUser","012345",1883);

 

void connect(STring,String,String,unsigned int)

Connect with an account credentials given hostname and port number.

 

SYNTAX
IOT.connect(hostname,username,password,portNumber);

 

RETURN
None.

 

PARAMETERS
-String object holding host name.
-String object holding username.
-String object holding password.
-Unsigned integer holding port number.

 

USAGE
String hostname = "test.mosquitto.org";
String username = "testUser";
String password = "012345";
IOT.connect(hostname,username,password,1883);

 

void disconnect(void)

Disconnects last connected session.

 

SYNTAX
IOT.disconnect();

 

RETURN
None.

 

PARAMETERS
None.

 

USAGE
IOT.disconnect();

 

void resetConnectionParametersToDefaults(void)

Reset last connection parameter values to default.

 

SYNTAX
IOT.resetConnectionParametersToDefaults();

 

RETURN
None.

 

PARAMETERS
None.

 

USAGE
IOT.resetConnectionParametersToDefaults();

 

void publish(const char*,byte *,byte,byte=0,bool
=false)

Publish raw data to topic given its data length.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-Const char array holding topic.
-Byte array holding payload (data).
-Byte holding data length.
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
byte payload[100] = "data";
IOT.publish("test/myboard/sensor",payload,100,QOS_0);

 

void publish(const char *,const char *,byte=0,
bool=false)

Publish string type data to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-Const char array holding topic.
-Const char array holding payload (data).
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
IOT.publish("test/myboard/sensor","data",QOS_0);

 

void publish(String,String,byte=0,bool=false)

Publish string type data to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-String object holding topic.
-String object holding payload (data).
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
String topic = "test/myboard/sensor";
String payload = "data";
IOT.publish(topic,payload,QOS_0);

 

void publish(const char *,int,byte=0,bool=false)

Publish signed integer data to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-Const char array holding topic.
-Signed integer holding payload (data).
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
int data = -123;
IOT.publish("test/myboard/sensor",data,QOS_0);

 

void publish(String,int,byte=0,bool=false)

Publish signed integer data to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-String object holding topic.
-Signed integer holding payload (data).
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
String topic = "test/myboard/sensor";
int data = -123;
IOT.publish(topic,data,QOS_0);

 

void publish(const char *,unsigned int,byte=0,
bool=false)

Publish unsigned integer data to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-Const char array holding topic.
-Unsigned integer holding payload (data).
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
unsigned int data = 123;
IOT.publish("test/myboard/sensor",data,QOS_0);

 

void publish(String,unsigned int,byte=0,bool
=false)

Publish unsigned integer data to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-String object holding topic.
-Unsigned integer holding payload (data).
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
String topic = "test/myboard/sensor";
unsigned int data = 123;
IOT.connect(topic,data,QOS_0);

 

void publish(const char *,float,byte=0,bool=false)

Publish float data to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-Const char array holding topic.
-Float holding payload (data).
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
float data = 123.123;
IOT.publish("test/myboard/sensor",data,QOS_0);

 

void publish(String,float,byte=0,bool=false)

Publish float data to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.publish(topic,payload,qos,retain);

 

RETURN
None.

 

PARAMETERS
-String object holding topic.
-Float holding payload (data).
-Byte holding QOS (quality of service). (default = QOS_0)
-Boolean holding Yes ‘true’ or No ‘false’ for retain message.(default = false)

 

USAGE
float data = 123.123;
IOT.publish("test/myboard/sensor",data,QOS_0);

 

void subscribe(const char *,byte=0)

Subscribe to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.subscribe(topic,qos);

 

RETURN
None.

 

PARAMETERS
-Const char array holding topic.
Byte holding QOS (quality of service). (default = QOS_0)

 

USAGE
IOT.subscribe("test/myboard/sensor",QOS_0);

 

void subscribe(String,byte=0)

Subscribe to topic.

LITERALS

QOS_0
QOS_1
QOS_2

 

SYNTAX
IOT.subscribe(topic,qos);

 

RETURN
None.

 

PARAMETERS
-String object holding topic.
Byte holding QOS (quality of service). (default = QOS_0)

 

USAGE
String topic = "test/myboard/sensor";
IOT.subscribe(topic,QOS_0);

 

void unsubscribe(void)

Unsubscribe all topics.

 

SYNTAX
IOT.unsubscribe();

 

RETURN
None.

 

PARAMETERS
None.

 

USAGE
IOT.unsubscribe();

 

void unsubscribe(const char *)

Unsubscribe topic.

 

SYNTAX
IOT.unsubscribe(topic);

 

RETURN
None.

 

PARAMETERS
Const char array holding topic.

 

USAGE
IOT.unsubscribe("test/myboard/sensor");

 

void unsubscribe(String)

Unsubscribe topic.

 

SYNTAX
IOT.unsubscribe(topic);

 

RETURN
None.

 

PARAMETERS
String object holding topic.

 

USAGE
String topic = "test/myboard/sensor";
IOT.unsubscribe(topic);

 

void setOnConnectionStatusChange(void (userFunction)(byte))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new connection status received.

 

LITERALS

CONNECTION_SUCCESSFUL
CONNECTION_FAILED
CONNECTION_LOST
CONNECTION_LOST_RECONNECTING
NOT_CONNECTED_YET
MISSING_HOST

 

SYNTAX
IOT.setOnConnectionStatusChange(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnConnectionStatusChanged(&connectionFunction);
}
void loop(){}
void connectionFunction(byte connectionStatus)
{ 
  /* Check connection code and display. */
  switch(statusCode)
  {
    case CONNECTION_SUCCESSFUL: Terminal.println("CONNECTION_SUCCESSFUL");break;
    case CONNECTION_FAILED: Terminal.println("CONNECTION_FAILED");break;
    case CONNECTION_LOST: Terminal.println("CONNECTION_LOST");break;
    case CONNECTION_LOST_RECONNECTING: Terminal.println("CONNECTION_LOST_RECONNECTING");break;
    case NOT_CONNECTED_YET:  Terminal.println("NOT_CONNECTED_YET");break;
    case MISSING_HOST: Terminal.println("MISSING_HOST");break;
  }
}

 

void setOnNewMessage(void (userFunction)(char *,byte *,byte,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(char * topic,byte * payload,byte payloadLength,byte qos, bool retain)
{ 
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
  for(int i=0;i<payloadLength;i++)
  {Terminal.write(payload[i]);}
}

 

void setOnNewMessage(void (userFunction)(char *,char *,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(char * topic,char * payload, byte qos, bool retain)
{ 
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
  Terminal.print("Payload =");
  Terminal.println(payload);
}

 

void setOnNewMessage(void (userFunction)(String,String,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(String topic,String payload, byte qos, bool retain)
{ 
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
  Terminal.print("Payload =");
  Terminal.println(payload);
}

 

void setOnNewMessage(void (userFunction)(char *,int,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(char * topic,int payload, byte qos, bool retain)
{ 
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
  Terminal.print("Payload =");
  Terminal.println(payload);
}

 

void setOnNewMessage(void (userFunction)(String,int,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(String topic,int payload, byte qos, bool retain)
{ 
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
  Terminal.print("Payload =");
  Terminal.println(payload);
}

 

void setOnNewMessage(void (userFunction)(char *,unsigned int,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(char * topic,unsigned int payload, byte qos, bool retain)
{ 
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
  Terminal.print("Payload =");
  Terminal.println(payload);
}

 

void setOnNewMessage(void (userFunction)(String,unsigned int,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(String topic,unsigned int payload, byte qos, bool retain)
{ 
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
  Terminal.print("Payload =");
  Terminal.println(payload);
}

 

void setOnNewMessage(void (userFunction)(char *,float,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(char * topic,float payload, byte qos, bool retain)
{ 
  float data = payload;
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
}

 

void setOnNewMessage(void (userFunction)(String,float,byte,bool))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new message received from a subscribed topic.

 

SYNTAX
IOT.setOnNewMessage(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data reveived to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnNewMessage(&myMessage);
}
void loop(){}
void myMessage(String topic,float payload, byte qos, bool retain)
{ 
  float data = payload;
  /* Display connection status over terminal. */
  Terminal.print("Topic =");
  Terminal.println(topic);
}

 

void setOnError(void (userFunction)(byte)

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once an error received.

 

LITERALS

CONNECTION_REFUSED
ILLEGAL_MESSAGE_RECEIVED
DROPPING_OUT_GOING_MESSAGE
ENCODER_NOT_READY
INVALID_CONNACK_RECEIVED
NO_CONNACK_RECEIVED
CONNACK_UNACCEPTABLEP_ROTOCOLVERSION
CONNACK_IDENTIFIER_REJECTED
CONNACK_SERVER_UNAVAILABLE
CONNACK_AUTHENTICATION_FAILED
CONNACK_NOT_AUTHORIZED
CONNACK_RESERVED

 

SYNTAX
IOT.setOnError(&userFunction);

 

RETURN
None.

 

PARAMETERS
&userFunction takes the physical address of your created function in the memory, and called once new data received to execute it’s functionality.

 

USAGE
void steup()
{
  OneSheeld.begin();
  IOT.setOnError(&error);
}
void loop(){}
void error(byte error)
{ 
  /* Check error code and display. */
  switch(errorCode)
  {
    case CONNECTION_REFUSED                    : Terminal.println("CONNECTION_REFUSED");break;
    case ILLEGAL_MESSAGE_RECEIVED              : Terminal.println("ILLEGAL_MESSAGE_RECEIVED");break;
    case DROPPING_OUT_GOING_MESSAGE            : Terminal.println("DROPPING_OUT_GOING_MESSAGE");break;
    case ENCODER_NOT_READY                     : Terminal.println("ENCODER_NOT_READY");break;
    case INVALID_CONNACK_RECEIVED              : Terminal.println("INVALID_CONNACK_RECEIVED");break;
    case NO_CONNACK_RECEIVED                   : Terminal.println("NO_CONNACK_RECEIVED");break;
    case CONNACK_UNACCEPTABLEP_ROTOCOLVERSION  : Terminal.println("CONNACK_UNACCEPTABLEP_ROTOCOLVERSION");break;
    case CONNACK_IDENTIFIER_REJECTED           : Terminal.println("CONNACK_IDENTIFIER_REJECTED");break;
    case CONNACK_SERVER_UNAVAILABLE            : Terminal.println("CONNACK_SERVER_UNAVAILABLE");break;
    case CONNACK_AUTHENTICATION_FAILED         : Terminal.println("CONNACK_AUTHENTICATION_FAILED");break;
    case CONNACK_NOT_AUTHORIZED                : Terminal.println("CONNACK_NOT_AUTHORIZED");break;
    case CONNACK_RESERVED                      : Terminal.println("CONNACK_RESERVED");break;
  }
}