Passing data

Now that we can return complex data from the WiFire, it's time to learn how to send it.

As well as XMLNode for returning data, we have ReadableXMLNode for reading data.

Reading data on the WiFire

Let's make our goal to be able to manually control the state of the LED. Rather than what we had previously where we could toggle the state, we will now make it so that the state is set to a specified value in the command parameters.

We can use the following structure

<state>
  ON
</state>

and choose either ON of OFF for our state.

Starting from the sketch we had for toggling the state of the LED we can then access values within the ReadableXMLNode. Using the function getChild we can navigate into the state node within the parameters.

ReadableXMLNode stateNode = params.getChild("state");

and then extract the content with getValue.

char *stateContent = stateNode.getValue();

In order to check what the desired state is we need to define the strings we want to compare against.

#define STATE_ON "ON"
#define STATE_OFF "OFF"

We can then compare the state content with the possible values.

if (strncmp(stateContent, STATE_ON, strlen(STATE_ON)) == 0)
{
  led1 = HIGH;
} 
else if (strncmp(stateContent, STATE_OFF, strlen(STATE_OFF)) == 0)
{
  led1 = LOW;
}

The completed sketch can be found here.

For more on how to access data and navigate the doctree of readable XML nodes, check the api reference.

Sending data from MakeItFlow

It's time to add custom payload support to MakeItFlow. I have created a new branch based on enhanced-output called command-parameters which contains the necessary changes to allow setting command parameters. As with the enhanced-ouput branch, you can either check out this branch here or download the compiled APK from the release page.

As you can see we are now able to send XML data to the WiFire.


From here you should have a good starting point for writing your own applications using FlowCloud. You can use any of the versions of MakeItFlow as a starting point for Android and you can easily create new Arduino sketches using Flow.

Remember that you have access to all of the FlowCloud API, reference available here and you are not required to use the command handler provided by the MPIDE FlowCloud extension - you can implement this all yourself in a different way if you wish.

For the rest of this blog I will be documenting my progress of creating a "geofence" application using Flow on Arduino. I'll work on the WiFire allowing it to log its GPS location and generate alerts when a geofence is escaped. I'll also provide a client based on MakeItFlow, showing the points on a map and allowing configuration of the logging and geofence.

So read on to see how a larger project can use FlowCloud on Arduino.