Skip to content
Daniel Berenguer edited this page Jan 4, 2016 · 4 revisions

This page describes the old TCP/IP interface provided by older versions of lagarto. ZeroMQ is no longer used by lagarto (lagarto-swap) and lagarto-max has been deprecated. Instead, lagarto implements MQTT and relies on third-party software such as node-red for the decisional part and the integration with other third-party solutions

Introduction

Lagarto-MAX is the lagarto process that receives, re-sends and processes events transmitted from any lagarto server running on the same IP network. Lagarto-MAX is a key piece into the lagarto architecture since it's able to integrate real values belonging to different networks and present them to the user in a homogeneous way. Moreover, being user-programmable, Lagarto-MAX can take decisions based on time or network events.

Features

Lagarto-MAX, due to its nature, is one of those components that will be continuously growing in functionalities. The following is a list of features provided by this lagarto client:

  • Reception of network events from any lagarto server on the same IP network (LAN or Internet)
  • Transmission of commands to any lagarto server on the same IP network (LAN or Internet)
  • Common web control/monitoring interface for all lagarto endpoints
  • Event manager entirely programmable from the Web interface
  • Automatic upload of values to different cloud data services (Xively, ThinkSpeak, Open sense, GroveStreams, Twitter)
  • Simple thread-independent interface for running user Python scripts.
  • Python API for managing values such as "get_value" or "set_value".
  • Local database (SQLite) storage of values.
  • On-the-fly creation of web graphs and charts.

Configuration

Lagarto-MAX is almost entirely configured from the web interface. Default HTTP port is 8002 so in order to access the web interface we have to open the following URL:

http:\\ip_address:8002

Lagarto settings

Every lagarto process needs some configuration parameters to be edited from this page:

  • Process name: name of the lagarto process. This name has to be unique across all lagarto process
  • Broadcast channel: TCP/IP address and port to be used for notifications. This channel must be the same for all lagarto processes.
  • HTTP server port: unique for each lagarto process running in the same machine.Default value is 8002.

Lagarto-MAX as a network hub

Lagarto-MAX is a central piece in the lagarto ecosystem, not only for its wide functionality but also because it acts as a hub between servers and clients.

In order for lagarto-max to run as the central hub or concentrator, it has to be started before any other lagarto process. Then, lagarto servers need to connect to lagarto-max via its broadcast port, that is the one being configured from the lagarto settings page. Finally, lagarto clients will connect to lagarto-max via the secondary broadcast port, that is the main broadcast port + 1.

Event programming

Programming events from the web interface is simple and intuitive. The Event Panel lists all the programmed events and lets us create new ones by pressing the "New Event" button:

Each event page shows three different sections: triggers. additional conditions and actions.

  • Triggers are initial conditions required to start an action. We can create multiple triggers on a single event but only one of them has to be fulfilled in order to run the subsequent actions. Two different types: lagarto network conditions and time conditions.
  • Additional conditions don't trigger the event by themselves but all of them must be fulfilled. Two different types: lagarto network conditions and time conditions.
  • Actions. Two different types: lagarto network conditions and cloud data service.

Defining new triggers and additional conditions is just a matter of pressing the "New" button and fill each requested field.

And the same applies for actions. The following is an example of lagarto value being pushed to Xively:

In summary. the web event editor provides a simple interface for programming the behaviour of any lagarto network based on the event-action paradigm.

Custom Python scripts

Lagarto-MAX also provides a scripting mechanism for those wanting to develop their own Python scripts. "scripts/events.py" is the starting point for any user-defined event. This Python module contains a method named "event_handler". This method is called once per minute and whenever a network value changes. This method has two arguments: "evnsrc" that shows the nature of the event (network and clock), and "evnobj", containing the related event object (lagarto endpoint or time data). Example of user code:

def event_handler(evnsrc, evnobj):
    """
    Event handling function
    
    @param evnsrc: event source ("network", "clock")
    @param evnobj: event object
    
    evnsrc = "network" -> evnobj = lagarto endpoint
    evnsrc = "clock" -> evnobj = time.localtime() object
    """
    
    if evnsrc == "network":
        print time.strftime("%d %b %Y %H:%M:%S", time.localtime()), evnobj
        
        value = network.get_value("SWAP-network.SWAP.Temperature")
        print "Temperature =", value
    elif evnsrc == "clock":
        print time.strftime("%d %b %Y %H:%M:%S", evnobj), "Time event"

The above is just an example. Users are allowed to develop large amounts of code and place them in separate modules, import Python libraries, run independent threads, etc.

NetworkAPI

In order to interact with lagarto networks, Lagarto-MAX provides the class api.NetworkAPI. The following are some of the methods provided by this API:

def get_endpoint(endp):
    """
    Get Lagarto endpoint
        
    @param endp: endpoint identification string
    format 1: process.location.name
    format 2: process.id
        
    @return lagarto endpoint object
    """

    def get_value(endp):
        """
        Get endpoint value
        
        @param endp: endpoint identification string
        format 1: process.location.name
        format 2: process.id
        
        @return endpoint value
        """

    def set_value(endp, value):
        """
        Set endpoint value
        
        @param endp: endpoint identification string
        format 1: process.location.name
        format 2: process.id
        @param value: new endpoint value
        
        @return endpoint value
        """

Example of use:

from api import NetworkAPI as network

# Lagarto endpoint
endpoint = network.get_endpoint("SWAP-network.SWAP.Temperature")

print endpoint.name, "in", endpoint.location, "is", endpoint.value, endpoint.unit

# The above code prints the same result as the following:
value = network.get_endpoint("SWAP-network.SWAP.Temperature")

print "Temperature in SWAP is", value, " C"

CloudAPI

CouldAPI provides direct mechanisms to push data to any of the supported cloud services:

    def push_pachube(endp, sharing_key, feed_id, datastream_id):
        """
        Push data to pachube

        @param endp: endpoint identification string
        format 1: process.location.name
        format 2: process.id        
        @param sharing_key: Pachube sharing key
        @param feed_id: Pachube feed ID
        @param datastream_id: Pachube datastream ID
        
        @return HTTP response from Pachube
        """
    def push_thingspeak(endp, api_key, field_id):
        """
        Push data to ThingSpeak

        @param endp: endpoint identification string
        format 1: process.location.name
        format 2: process.id        
        @param api_key: ThingSpeak API key
        @param field_id: ThingSpeak field ID
        
        @return HTTP response from ThingSpeak
        """

Example of use

from api import CloudAPI as cloud

# Push humidity value to Pachube
cloud.push_pachube("SWAP-network.SWAP.Humidity",
                   "cykPX_p0wDMmAm8VDXXel3lqv8-SAKx4UlFJT3lyYWhSND0g",
                   "54081",
                   "10.12.1")

# And push it to ThingSpeak too
cloud.push_thingspeak("SWAP-network.SWAP.Humidity",
                      "VTPX8MN9BFZ7M8MZ",
                      "field2")

Supported cloud data services

Any value can be pushed to the following cloud services via custom scripting or web event:

About AutoRemote

AutoRemote acts as a messaging bus across a number of different platforms and applications. Very useful for pushing endpoint information to Android/iOS.

Usage Note

Message - Formatting string. The following are placeholders that can be used. When the message is sent, Lagarto will replace the placeholders with the relevant enpoint information. Ex: "${id} ${location} ${name} ${type} ${value} ${unit}=:=${name} is now ${value}"

  • ${id}
  • ${location}
  • ${name}
  • ${type}
  • ${direction}
  • ${value}
  • ${unit}

Anti Swap

API for Anti Swap

Clone this wiki locally