Close

Designing the API

A project log for Iota: Internet of things for all

A low cost Internet of things platform to build your own smart house

nathanandrewwilliamsnathan.andrew.williams 07/06/2014 at 05:020 Comments

Early on in this project I was set on delivering a lot consistently, but I just couldn't keep the pace up.

Somewhere in those early days I started hacking some "test code" together and it was a mess.

So ignore the code currently in GitHub, it is all being rewritten, but first I need to design upfront.


Iota API design

So this project log is about the design of the Iota API.

This is what I have so far:

Setup

Iota.begin(trigger_pin)

Publishing

topic_id = Iota.register_topic(TOPIC_NAME) 

Iota.send(topic_id, data, len)

Receiving

topic_id = Iota.register_callback(TOPIC_NAME, my_func) 

void my_func(uint8_t topic_id, uint8_t *data, uint8_t length) {} 


The way you would use this is to call setup on the Iota module, and give it a trigger pin (more on that later, ignore for now).

Sensors

Now, if you are building a pure sensor, you would only need the publishing methods.

The first publishing method registers an MQTT topic name with the system, which gives you a numerical id for that topic.

From here you can have your code sit in a loop taking samples, sending them through Iota and maybe sleep a little while to save power.

Actuators

If your node is out to perform some action, such as turning something on, you would pay more attention to the receiving methods.

The first receiving method registers an MQTT topic name and a callback.

When the node is sent a message, Iota will decode the message and activate the callback function for that topic name.

The basic code structure here would be to register events you are interested in and provide a function to act on that event, and then sleep until Iota wakes you, saving battery power.

Mixed Nodes

Of course a node doesn't have to be just one or the other.

In some cases you might want to sensor something and react.

For a node like this you might set a timer to wake the node up, take a measurement, send the reading and go back to sleep. At the same time, you have callbacks registered which will also wake the node when an incoming message is received so you can act on it, and once again go back to sleep.


Now this is an early document and the design might change as it is being developed and tested.

I am open to suggestions if you see an area I am missing, or a better way to do something.

Or if you are wondering how you would do something, ask and we can check that it can be done with the above API.

Discussions