Skip to content

Different nodes with different features

Christophe de Dinechin edited this page Jul 22, 2015 · 1 revision

Different Nodes with Different Features

(Contributed by Jim Schimpf)

Example of ELIOT use

When you are building an IOT system, the nodes probably won't be all of the same type. That is, you might have some RaspberryPi's. some Beagle Bone Black's and controlling it all a PC running Linux. ELIOT is used then to query or command these clients to do various functions say for temperature or control. In that case you might send out queries to all the clients asking for temperature readings and then based on these you might sent back commands to run a fan or turn up the heat.

In this case we have different machines but would need to have similar functions on each, that is sending a "Temperature", or "FanON" request to each would produce the same result even though the hardware, operating system or API is different.

How it works

ELIOT makes this quite simple. You just write a module file (.tbl) for each of the clients with supporting C++/C files to handle the hardware/OS issues. For consistency, it is better if all of the functions in your .tbl file have the same input and output parameters and calling sequence, although this is not strictly speaking mandatory. Once you do this then add these to each of the ELIOT builds for each machine and build them.

Probably the best way to do this is to use the same .tbl file for each of the implementations and then put all the node specific stuff in the backing C++/C files.

Example

In this example we have an OS X system (192.168.1.127) and an Ubuntu sysem (192.168.1.106) and we have a very simple function rTest that just returns a string (different for each system).

Contents of .tbl file

I made a new .tbl (ELIOT module) called rTest. This will be used on both the linux and OS X system.

// ***************************
//  rtest.tbl
// ***************************
// 
//   File Description:
// 
//     This module calls a C++ function that returns a string
//		The function sys_text() is unique for each system  
//
// **************************
// 
// ***************************

NAME_FN(rTest,            		// Unique internal name
    text,                   	// Return value
    "rTest",          			// Name for ELIOT programmers
    char *txt = sys_text();
    R_TEXT(txt);
    );

Then I added this to the modules line in the Makefile

C++ file

We are going to write a different C++ for OS X and UBUNTU. Because we are just returning a text string these won't be that different but you get the idea that these can be totally different and use different API's.

Include file

#ifndef RTEST_H
#define RTEST_H
// ***************************  
//  rtest.cpp  
// ***************************  
//
//   File Description:
//
//    Return a specific text for OSX
//
// ***************************  

#include <string.h>

ELIOT_BEGIN

char *sys_tex(void);

ELIOT_END
#endif

C++ file for OS X

// ***************************
//  rtest.cpp
// ***************************
//
//   File Description:
//
//    Return a specific text on OS X
//
// ***************************

#include "rtest.h"

ELIOT_BEGIN

char *sys_text(void)
{
	char *rtn = (char *)"\nHello from OS X\n";
	
	return rtn;
}

ELIOT_END

C++ file for UBUNTU

This one is much more complex. It reads the debian_version and tacks that one the string we are outputting.

// ***************************
//  rtest.cpp
// ***************************
//
//   File Description:
//
//    Return a text describing system on Ubuntu
//
// ***************************
// ***************************

#include "rtest.h"

ELIOT_BEGIN

static char buffer[50];

char *sys_text(void)
{
	FILE *fd;
	char fbuf[30];
	char *rtn = (char *)"ERROR";

	// Open the debian version file
	fd = fopen("/etc/debian_version","r");
	if( fd != NULL )
	{
		fread(fbuf,1,30,fd);
		fclose(fd);
		sprintf(buffer,"Hello from Ubuntu %s",fbuf);
		rtn = (char *)&(buffer[0]);
	}
	return rtn;
}

ELIOT_END

Building ELIOT

Edit the modules line in the OS X and the Ubuntu version

MODULES=basics io math text remote time-functions temperature rtest   

and build.

Scripts

We now build to eliot script files.

OS X

tell "192.168.1.127",
    writeln rTest

Ubuntu

tell "192.168.1.106",
    writeln rTest

We now run this from OS X ELIOT

OS X -> OS X  
543 ElIoT> eliot rtest.eliot   
0  
515 ElIoT> eliot -l    
This is an OS X test

Now run this from OSX -> UBUNTU Without adding rTest to the Ubuntu version of ELIOT

544 ElIoT> eliot urtest.eliot  
rTest								Ubuntu

After adding rtest.tbl to makefile of Ubuntu version

546 ElIoT> eliot rtest.eliot 		OS X  
Hello from Ubuntu jessie/sid		Ubuntu