ITTIoT framework

Code structure

The following image shows the typical code structure when creating a program with the ITTIoT framework. The program is structured as following:

  • Includes and global variables - here you include any libraries you need as well as create global variables.
  • iot_received() - this callback function is called when the module receives a message from a subscribed topic. Messages from all topics call the same function, so switching based on the topic is required.
  • iot_connected() - this callback function is called when the module first connects to the broker. Here you should subscribe to topics.
  • Setup - regular Arduino setup. But be sure to include a call to iot.setup() method.
  • Main loop - regular Arduino main loop. Be sure to include iot.handle() to each iteration.

List of ITTIoT framework methods

MethodDescription
iot.setup()Sets up the ITTIoT framework and connects to the broker.
iot.printConfig()Prints the configuration of the module to the serial.
iot.handle()Does the necessary background work for the operation of the framework. For example it checks if any new messages have been received and if necessary, calls the callback methods. This method has to be called periodically in the main loop.
iot_connected()Callback function that is defined by the user. This method gets called when the module manages to connect to the broker. Mainly used to subscribe to topics.
iot.subscribe(String topic)Subscribes to the topic inserted as the operand. For example iot.subscribe(“livingroom/temp”) subscribes to the “livingroom/temp” topic.
iot_received(String topic, String msg) User defined callback method that gets called if any messages are received from subscribed topics. The user can then use the topic and message in his/her code.
iot.publishMsg(String topic, String msg)The module will publish a message to topic “controllername/topic”. Note that the method will automatically add the modules name behind the topic inserted. For example, publishing to topic “temp” will actually publish to topic “controllername/topic”. If this is undesirable then use the iot.publishMsgTo() method instead.
iot.publishMsgTo(String topic, String msg, bool retain)This method works similarly to the previous but does not add the module name to the topic. That means that messages published to “topic” will indeed be published to “topic”. With this method you can also choose if you want the broker to retain the last message received. If you are not interested in this, then leave it false)
en/iot/examples/setup/ittiot.txt · Last modified: 2019/02/20 15:47 by rim.puks
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0