Owl Intuition Multicast not working on emoncms raspberry pi sd image (SOLVED)

Hi all,

 

I have a owl intuition system and been using a python script to read owl's multicast feed and publish to emoncms.org

Last night I installed emoncms on my rpi as outlined in "RaspberryPI + Harddrive + Emoncms".

Everything is working fine, except the python script doesn't read the multicast feed... no errors, nothing, just sits there and nothing is read/sent to opencms...

I tried the same script on a "plain" raspbian install and it works fine...

I also tried a different C program which also doesn't work...

 

Seems I can't listen to multicast messages on port 22600 when using the opencms sd image, and can't figure out why...

 

Any ideas?

 

TIA, Gustavo Melo

 

The python script:

 

##################################################################

´GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library.  If not, see <http://www.gnu.org/licenses/>.

"""

from twisted.internet.protocol import DatagramProtocol
from lxml import objectify
from decimal import Decimal
import socket
import requests

sock = socket.socket(socket.AF_INET, # Internet
          socket.SOCK_DGRAM) # UDP

MCAST_ADDR = '224.192.32.19'
MCAST_PORT = 22600

class node(object):
# structure for storing data about channels
def __init__(self, channel_id, current_w, daily_wh):
#  self.channel_id = channel_id
  self.current_w = Decimal(current_w)
#  self.daily_wh = Decimal(daily_wh)

def __str__(self):
  return '%s' % (
#   self.channel_id,
   self.current_w,
#   self.daily_wh
  )

class OwlMessage(object):
def __init__(self, datagram):
  #print "datagram: %r" % (datagram,)
  self.root = objectify.fromstring(datagram)
 
  # there are also weather events -- we don't care about these
  assert (self.root.tag == 'electricity'), ('OwlMessage XML must have `electricity` root node (got %r).' % self.root.tag)
 
  # note that the MAC address is given by the message, not the packet.
  # this can be spoofed
  self.mac = self.root.attrib['id']
 
  # read signal information for the sensor's 433MHz link
  self.rssi = Decimal(self.root.signal[0].attrib['rssi'])
  self.lqi = Decimal(self.root.signal[0].attrib['lqi'])
 
  # read battery information from the sensor.
  self.battery = Decimal(self.root.battery[0].attrib['level'][:-1])
 
  # read sensors (channels)
  self.channels = {}
  for channel in self.root.chan:
   assert channel.attrib['id'] not in self.channels, 'Channel duplicate'
  
   assert channel.curr[0].attrib['units'] == 'w', 'Current units must be watts'
   assert channel.day[0].attrib['units'] == 'wh', 'Daily usage must be watthours'
  
   # we're good and done our tests, create a channel
   self.channels[channel.attrib['id']] = node(channel.attrib['id'], channel.curr[0].text, channel.day[0].text)

def __str__(self):
  return 'csv=%s' % (
   ','.join((str(x) for x in self.channels.itervalues()))
  )

class OwlIntuitionProtocol(DatagramProtocol):
def __init__(self, iface=''):
  """
  Protocol for Owl Intution (Network Owl) multicast UDP.
 
  :param iface: Name of the interface to use to communicate with the Network Owl.  If not specified, uses the default network connection on the cost.
  :type iface: str
  """
  self.iface = iface

def startProtocol(self):
  self.transport.joinGroup(MCAST_ADDR, self.iface)

def datagramReceived(self, datagram, address):
  msg = OwlMessage(datagram)
  self.owlReceived(address, msg)

def owlReceived(self, address, msg):
  print '%s' % (msg)
  curlmessage = '%s' % (msg)
  r = requests.post("http://localhost/emoncms/input/post.json?node=1&"+curlmessage+",""&apikey=XXXXXXXXXXXXXX")

if __name__ == '__main__':
from twisted.internet import reactor
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-i', '--iface', dest='iface', default='', help='Network interface to use for getting data.')

options = parser.parse_args()

protocol = OwlIntuitionProtocol(iface=options.iface)
reactor.listenMulticast(MCAST_PORT, protocol, listenMultiple=True)
reactor.run()

#########################################################################

GustavoMelo's picture

Re: Owl Intuition Multicast not working on emoncms raspberry pi sd image (SOLVED)

ok, feeling stupid but:

 

Solved by adding "sudo ufw allow 22600" :)

 

Thank you anyway,

 

Gustavo Melo

TrystanLea's picture

Re: Owl Intuition Multicast not working on emoncms raspberry pi sd image (SOLVED)

Great, yes sorry I should make a clearer note that there is a firewall installed as defaultt in the latest image as well as the other standard security things like disabling root access and mysql_sequre_install.

Nice to see the python script for interface with the owl, it would be great to include this in the usefulscripts repository, thats also installed as default with the harddrive image:

http://github.com/emoncms/usefulscripts

Do you use github? can you send me a pull request there?

GustavoMelo's picture

Re: Owl Intuition Multicast not working on emoncms raspberry pi sd image (SOLVED)

Hi,

 

I used the code from:

 

https://github.com/micolous/intuition

 

Just adapted it to post the results to emoncms and cleaned up the results to send just the power values...

 

But I can clean it up a bit and send it to you...

 

joshdinsdale's picture

Re: Owl Intuition Multicast not working on emoncms raspberry pi sd image (SOLVED)

hi Gustavo

 

Any chance you could make your script public, or perhaps send me a copy? I've tried using your pasted version but it crashes sometimes, it doesnt seem to be ignoring the heating values.

I'm not really coder but I am going to try and fix the problem. :)

 

Thanks

joshdinsdale's picture

Re: Owl Intuition Multicast not working on emoncms raspberry pi sd image (SOLVED)

Scratch that, it is working, just got to get to grips with emoncms now. :)

j20ands10's picture

Re: Owl Intuition Multicast not working on emoncms raspberry pi sd image (SOLVED)

rather a daft question I know but how do you run the script on raspbian?

Am interested in getting my owl system working with emoncms but no idea where to start

any help appriciated


 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.