#!/usr/bin/env python
from twisted.internet.protocol import DatagramProtocol
#from twisted.internet import epollreactor
#epollreactor.install()
import time
import sys                     
import datetime
import os



f=open("/var/log/domotika/domotika.log", "a")


class DomIka(DatagramProtocol):
 
   termostati={ 'uno': 'no', 'int': 'no', 'ter': 'no' }

   def datagramReceived(self, data, (host, port)):
      now =  datetime.datetime.now()
      print "%s (%d) -> received %r from %s:%d" % (now, time.time(), data, host, port)
      #print 'datagramReceived'
      f.write("%s (%d) -> received %r from %s:%d\n" % (now, time.time(), data, host, port))
      f.flush()
      #sys.stdout.write("%d -> received %r from %s:%d" % (time.time(), data, host, port))
      sys.stdout.flush()

      if data=='CAMPANELLO.CASA\r\n':
         #os.system('/usr/bin/mplayer /home/nextime/Working_old/Microchip/python/tools/campanello.wav')
         os.system('/usr/bin/beep -f 1000 -n -f 2000 -n -f 1500')

      elif data=='CAMPANELLO.UFFICIO\r\n':
         os.system('/usr/bin/beep -f 2000 -n -f 1000 -n -f 1500')
      """
      elif data=='TERMOSTATO.HI.PTER\r\n':
         if not 'lo' in 

      elif data=='TERMOSTATO.HI.PUNO\r\n':

      elif data=='TERMOSTATO.HI.PINT\r\n':

      elif data=='TERMOSTATO.LO.PTER\r\n':

      elif data=='TERMOSTATO.LO.PUNO\r\n':

      elif data=='TERMOSTATO.LO.PINT\r\n':
      """


if __name__ == '__main__':
   from twisted.internet import reactor
   reactor.listenUDP(12080, DomIka())
   reactor.run()
   

