Freedomotic Plugin

From openPicus Wiki
Jump to: navigation, search

Contents

Project Summary

Today building automation is hardware-centric, vendor-bound and if we talk of home automation it offers few services.

This leads respectively to a system hard to scale to your needs which easely becomes obsolete; strong vendor lock-in for the end user and high prices; low flexibility due to standardized automations or features "hard-coded" in the hardware facilities.

Freedomotic is here to solve this issues with an open, flexible, scalable and mashups oriented software that can interact with well known standard building automation protocols as long as with "do it yourself" solutions, and treats the web, social networks and frontends just like any other sensor or actuator in your automation system. This means you can twitt your washing machine to start the washing cycle.

Due to its abstraction layer and modular architecture it can manage from small appartments to huge buildings like museums and corporate offices. You can automate your home for free or, for example, if you run a shop or public place with Freedomotic you can easily create environment aware services for your customers delivered on their smartphones.

Freedomotic supports popular building automation technologies like BTicino OpenWebNet, Modbus RTU, X10 as well as custom automation projects using Arduino devices, do it yourself (DIY) boards, third party graphical frontends for Android, text to speech (TTS) engines, motion detection using IP cameras, social networks integration, for example Twitter, and much more... All this features are delivered from our marketplace as downloadable plugins.

DOWNLOAD Freedomotic whitepaper

The Concept

We are describing two different plugins to create an interaction between Freedomotic and Flyport.
The first requires only a Flyport board controlling its inputs/outputs lines.
The second uses a Grove Board to realize a complete sensors platform for environmental control.

Freedomotic Installation

Download the last Freedomotic version from our site.
Unzip the file and start Freedomotic. It requires a Java Virtual Machine v1.7.

Flyport Plugin

How the plugin works

The plugin reads the status of each flyport output by parsing the status.xml (specifically led0, led1, ... tags). To change the status it sends a GET request to leds.cgi adding the led line as parameter.

Flyport Plugin Installation

In "Plugins" menu choose "Install from marketplace". After the list is updated (it can take up to a minute) you will see the list of plugins on the markeplace that are available for your current Freedomotic version. To install one double click on Openpicus icon and follow the instructions.

How to control an object with this board

For this example we use a Freedomotic light object:

1. Open the file flyport-manifest.xml into freedomotic/plugins/devices/flyport folder and set ip-address and port number of your flyport board

2. Right click on the light object in the environment to show its configuration panel

3. Change the property "protocol" to "flyport" (showed in the list)

4. Change the property "address" to a string composed of IP_ADDRESS:PORT:LED_NUMBER where ip_address and port are the same of your Flyport and led_number is the led you want to control eg: 192.168.0.115:80:4 (led4 in the example)

5. Under "turn on" (in Commands Configuration) select the command called "Turn ON on Flyport board"

6. Under "turn off" (in Commands Configuration) select the command called "Turn OFF on Flyport board"

7. Under "powered" (in Triggers Configuration) select the command called "Flyport reads relay state change"

Double click on the object changes its status. The plugin is able to read any status change and update the object one. If you change the status of each configured light (by flyport webserver) the icon changes in according with the status (on/off). If you click on Freedomotic light icon you see the led switch on/off on the flyport.

Plugin source code

The source code is hosted here for any contribution or improvement.

Grove System Plugin

How the plugin works

The Freedomotic plugin acts as a simple udp server listening for packets from Grove Board boards. When it receives a packet, it extracts the data (Grove Board ip address, sensor connector, sensor value). Then it notifies the event on the Freedomotic messages channel and updated the specific object.

The firmware code is included in the taskFlyport.c. Let's analyze it step by step.

First of all the libraries required for Grove Board and analog temperature sensor are included.
#include "taskFlyport.h"
#include "grovelib.h"
#include "analog_temp.h"

Now let's create an integer variable for udp socket reference, a char array for sending messages and udp server ip address and port number. The last parameters are used by Freedomotic plugin. If you change these you must change also the flyport variables.

int clientUDPsocket;
char send[120];
 
void FlyportTask()
{	
BYTE Socket=0;    //UDP Socket
char *UDPPort="7331"; //UDP port
char *UDPAddress="192.168.1.100";

The next step is defining variables for Grove Board and used sensors and attaching them to the board. The float variables are used to store the new and the old sensors values.

 //GROVE board
void *board = new (GroveNest);
 
// GROVE devices
// Light sensor
void *light_sensor = new (An_i);
// Analog Temperature Sensor
void *temp_sensor = new(An_Temp);
 
// Sensor attached to board
attachToBoard(board, temp_sensor, AN1);
attachToBoard(board, light_sensor, AN3);
 
float lightVal = 0.0;
float lightValStored = 0.0;
float tempVal = 0.0;
float tempValStored = 0.0;

The application core is included into the infinite loop. It detects the new sensor value, compares it with the stored one and if there is a change sends a new udp packet to the Freedomotic server whit a prefixed message format: connector:sensorType:value. The char ":" is the string delimiter. The allowed sensor types are (in this example) temperature and luminosity. You can't change them without changing the Freedomotic plugin code because it makes a string parsing to extract the data. After the socket is closed.

while(1)
{
 vTaskDelay(500);
 //Socket=UDPClientOpen(UDPAddress,UDPPort);
 // Get the new temperature value
 tempVal = get(temp_sensor); 
 if(tempVal!=tempValStored) {
tempValStored=tempVal;
   sprintf(send,"AN1:temperature:%3.1f", (double)tempVal);
Socket=UDPClientOpen(UDPAddress,UDPPort);
   UDPWrite(Socket,send,strlen(send));  //Send the data trough the UDP
   UDPClientClose(Socket);
   }
 // Get the new luminosity value using the get() function
 lightVal = get(light_sensor);
 if(lightVal!=lightValStored) {
lightValStored=lightVal;
   sprintf(send,"AN3:luminosity:%3.0f", (double)lightVal);
Socket=UDPClientOpen(UDPAddress,UDPPort);
   UDPWrite(Socket,send,strlen(send));  //Send the data trough the UDP
   UDPClientClose(Socket);
   }	
}
}


No packets are sent if there is no sensor data change.
This reduces the network traffic.

The List of Materials

The build process

Software

Download the Grove System project package and extract it into a new folder.
Open the openPicus IDE, and from the environment open the project folder.
Click the “Compile” button, and when the operation is completed click “Download” so that the new firmware is downloaded in the Flyport's microcontroller.

Hardware

Let's connect the analog sensors to the Grove Board: temperature sensor to AN1 and light sensor to AN3.

Freedomotic grove system sensors.JPG

Then let's connect the flyport wifi module and the power supply.

Freedomotic grove system.JPG

Grove System Plugin Installation

Start Freedomotic by double click on its icon or by command line with java -jar freedomotic.jar.
The pc running Freedomotic must have 192.168.1.100 as ip address.
In "Plugins" menu choose "Install from marketplace". After the list is updated (it can take up to a minute) you will see all available plugin categories for your current Freedomotic version. Select Automation Protocols, then Openpicus Grove System icon and click on Install button following the video instructions.

Freedomotic marketplace.png

Plugin source code

The software is written in Java. You can find the source code on our GitHub official repository.
In particular
UDP Server
Freedomotic plugin

Showcase

This video shows the Openpicus Grove System plugin in action.


Project Open Issues

There is a lot of work to do. For example:

1. test the plugin with a lighting nest and create a video showing how to control your home lighting

2. add support for reading inputs from the modules

3. test the Grove System with more sensors


For more info please visit freedomotic.com or contact us at mauro[at]freedomotic.com
Official openpicus forum topic here
To discuss about the Grove System plugin please refer to this forum topic

Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox