Giter Club home page Giter Club logo

owl-packet-interceptor's Introduction

owl-packet-interceptor

Official repo stats

Build Status Coverage Status Scrutinizer Code Quality

###Description owl-packet-interceptor is a PHP library which intercepts and parses XML packets sent via UDP by an OWL Monitor.

To do so you first need to change the Data Push Settings on your OWL Intuition Dashboard providing IP address and port where you will install owl-packet-interceptor.

At the moment owl-packet-interceptor is able to handle packets coming from these devices:

###Structure owl-packet-interceptor is divided in four main packages:

  • Packet: Classes into which the packet is unmarshalled. The Packet package contains a sub-package for each kind of packet sent from OWL devices, for now only the Electricity and Solar packets type are supported. Each packet is represented by a main class (Electricity.php for electricity, Solar.php for solar) which implements the IPacket interface.
  • Listener: Contains the UDP Listener which intercepts packets sent from the device.
  • Parser: Contains the classes which are used to extract data from the XML packet. Each parser implements the interface IParser.
  • Storage: Contains the classes which handle the Packet representation. Each storage class implements the IStorage interface.

So:

  • the Listener intercepts a new packet,
  • the Parser extract data from the packet and build a new Packet object,
  • the Packet object in handled by the Storage

###Getting started

Create a new folder and move into it

Install owl-packet-interceptor

$ composer require dalen/owl-packet-interceptor:dev-master

Create a new php file, say App.php, and write something like:

<?php

require_once('./vendor/autoload.php');

use Dalen\OWLPacketInterceptor\Listener\UDPListener;
use Dalen\OWLPacketInterceptor\Storage\StdOutStorage;
use Dalen\OWLPacketInterceptor\Parser\Parser;

// create listener on port 8000
$listener = new UDPListener('0.0.0.0',8000);
// create a new parser
$parser = new Parser();
// create standard output storage (outputs on the console) 
$storage = new StdOutStorage();

// listen for new packets
while(true)
{
    // pass the XML string to the parser
    $parser->setXMLString($listener->read());
    // make the storage handle the Packet object extracted by the parser
    $storage->storePacket($parser->parse());
}

Run App.php

$ php App.php

Open a new shell and try to send a packet

$ echo -n "<electricity id='AA12345679'><signal rssi='-86' lqi='91'/><battery level='100%'/><chan id='0'><curr units='w'>1288.00</curr><day units='wh'>9904.89</day></chan></electricity>" | nc -4u -q1 127.0.0.1 8000 > /dev/null 2>/dev/null &

App.php should print

This is an Electricity Packet

Now you're ready to write your own Storage!

###License

MIT

owl-packet-interceptor's People

Contributors

danieleorler avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

owl-packet-interceptor's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.