New initial version

This commit is contained in:
root
2026-06-21 18:42:39 +00:00
commit 009484197f
45 changed files with 5538 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Example on getting the information about the EnOcean controller.
The sending is happening between the application and the EnOcean controller,
no wireless communication is taking place here.
The command used here is specified as 1.10.5 Code 03: CO_RD_VERSION
in the ESP3 document.
"""
from enocean.consolelogger import init_logging
from enocean.communicators.serialcommunicator import SerialCommunicator
from enocean.protocol.packet import Packet
from enocean.protocol.constants import PACKET
from enocean import utils
import traceback
import sys
try:
import queue
except ImportError:
import Queue as queue
init_logging()
"""
'/dev/ttyUSB0' might change depending on where your device is.
To prevent running the app as root, change the access permissions:
'sudo chmod 777 /dev/ttyUSB0'
"""
communicator = SerialCommunicator(port=u'/dev/ttyUSB0', callback=None)
packet = Packet(PACKET.COMMON_COMMAND, [0x03])
communicator.daemon = True
communicator.start()
communicator.send(packet)
while communicator.is_alive():
try:
receivedPacket = communicator.receive.get(block=True, timeout=1)
if receivedPacket.packet_type == PACKET.RESPONSE:
print('Return Code: %s' % utils.to_hex_string(receivedPacket.data[0]))
print('APP version: %s' % utils.to_hex_string(receivedPacket.data[1:5]))
print('API version: %s' % utils.to_hex_string(receivedPacket.data[5:9]))
print('Chip ID: %s' % utils.to_hex_string(receivedPacket.data[9:13]))
print('Chip Version: %s' % utils.to_hex_string(receivedPacket.data[13:17]))
print('App Description Version: %s' % utils.to_hex_string(receivedPacket.data[17:]))
print('App Description Version (ASCII): %s' % str(bytearray(receivedPacket.data[17:])))
except queue.Empty:
continue
except KeyboardInterrupt:
break
except Exception:
traceback.print_exc(file=sys.stdout)
break
if communicator.is_alive():
communicator.stop()
+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from enocean.consolelogger import init_logging
import enocean.utils
from enocean.communicators.serialcommunicator import SerialCommunicator
from enocean.protocol.packet import RadioPacket
from enocean.protocol.constants import PACKET, RORG
import sys
import traceback
try:
import queue
except ImportError:
import Queue as queue
def assemble_radio_packet(transmitter_id):
return RadioPacket.create(rorg=RORG.BS4, rorg_func=0x20, rorg_type=0x01,
sender=transmitter_id,
CV=50,
TMP=21.5,
ES='true')
init_logging()
communicator = SerialCommunicator()
communicator.start()
print('The Base ID of your module is %s.' % enocean.utils.to_hex_string(communicator.base_id))
if communicator.base_id is not None:
print('Sending example package.')
communicator.send(assemble_radio_packet(communicator.base_id))
# endless loop receiving radio packets
while communicator.is_alive():
try:
# Loop to empty the queue...
packet = communicator.receive.get(block=True, timeout=1)
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.VLD:
packet.select_eep(0x05, 0x00)
packet.parse_eep()
for k in packet.parsed:
print('%s: %s' % (k, packet.parsed[k]))
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.BS4:
# parse packet with given FUNC and TYPE
for k in packet.parse_eep(0x02, 0x05):
print('%s: %s' % (k, packet.parsed[k]))
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.BS1:
# alternatively you can select FUNC and TYPE explicitely
packet.select_eep(0x00, 0x01)
# parse it
packet.parse_eep()
for k in packet.parsed:
print('%s: %s' % (k, packet.parsed[k]))
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.RPS:
for k in packet.parse_eep(0x02, 0x02):
print('%s: %s' % (k, packet.parsed[k]))
except queue.Empty:
continue
except KeyboardInterrupt:
break
except Exception:
traceback.print_exc(file=sys.stdout)
break
if communicator.is_alive():
communicator.stop()
+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from enocean.consolelogger import init_logging
import enocean.utils
from enocean.communicators.serialcommunicator import SerialCommunicator
from enocean.protocol.packet import RadioPacket
from enocean.protocol.constants import PACKET, RORG
import sys
import traceback
try:
import queue
except ImportError:
import Queue as queue
def assemble_radio_packet(transmitter_id):
return RadioPacket.create(rorg=RORG.BS4, rorg_func=0x20, rorg_type=0x01,
sender=transmitter_id,
CV=50,
TMP=21.5,
ES='true')
init_logging()
communicator = SerialCommunicator()
communicator.start()
print('The Base ID of your module is %s.' % enocean.utils.to_hex_string(communicator.base_id))
if communicator.base_id is not None:
print('Sending example package.')
communicator.send(assemble_radio_packet(communicator.base_id))
# endless loop receiving radio packets
while communicator.is_alive():
try:
# Loop to empty the queue...
packet = communicator.receive.get(block=True, timeout=1)
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.VLD:
packet.select_eep(0x05, 0x00)
packet.parse_eep()
for k in packet.parsed:
print('%s: %s' % (k, packet.parsed[k]))
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.BS4:
# parse packet with given FUNC and TYPE
for k in packet.parse_eep(0x02, 0x05):
print('%s: %s' % (k, packet.parsed[k]))
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.BS1:
# alternatively you can select FUNC and TYPE explicitely
packet.select_eep(0x00, 0x01)
# parse it
packet.parse_eep()
for k in packet.parsed:
print('%s: %s' % (k, packet.parsed[k]))
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.RPS:
for k in packet.parse_eep(0x02, 0x02):
print('%s: %s' % (k, packet.parsed[k]))
except queue.Empty:
continue
except KeyboardInterrupt:
break
except Exception:
traceback.print_exc(file=sys.stdout)
break
if communicator.is_alive():
communicator.stop()
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
Example to show automatic UTE Teach-in responses using
http://www.g-media.fr/prise-gigogne-enocean.html
Waits for UTE Teach-ins, sends the response automatically and prints the ID of new device.
'''
import sys
import time
import traceback
import enocean.utils
from enocean.communicators import SerialCommunicator
from enocean.protocol.packet import RadioPacket, UTETeachInPacket
from enocean.protocol.constants import RORG
try:
import queue
except ImportError:
import Queue as queue
def set_position(destination, percentage):
global communicator
communicator.send(
RadioPacket.create(rorg=RORG.VLD, rorg_func=0x05, rorg_type=0x00, destination=destination, sender=communicator.base_id, command=1, POS=percentage)
)
communicator = SerialCommunicator()
communicator.start()
print('The Base ID of your module is %s.' % enocean.utils.to_hex_string(communicator.base_id))
# set_position([0x05, 0x0F, 0x0B, 0xEA], 100)
# time.sleep(10)
set_position([0x05, 0x0F, 0x0B, 0xEA], 50)
print('Press and hold the teach-in button on the plug now, till it starts turning itself off and on (about 10 seconds or so...)')
devices_learned = []
# endless loop receiving radio packets
while communicator.is_alive():
try:
# Loop to empty the queue...
packet = communicator.receive.get(block=True, timeout=1)
if isinstance(packet, UTETeachInPacket):
print('New device learned! The ID is %s.' % (packet.sender_hex))
devices_learned.append(packet.sender)
except queue.Empty:
continue
except KeyboardInterrupt:
break
except Exception:
traceback.print_exc(file=sys.stdout)
break
print('Devices learned during this session: %s' % (', '.join([enocean.utils.to_hex_string(x) for x in devices_learned])))
if communicator.is_alive():
communicator.stop()
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
Example to show automatic UTE Teach-in responses using
http://www.g-media.fr/prise-gigogne-enocean.html
Waits for UTE Teach-ins, sends the response automatically and prints the ID of new device.
'''
import sys
import time
import traceback
import enocean.utils
from enocean.communicators import SerialCommunicator
from enocean.protocol.packet import RadioPacket, UTETeachInPacket
from enocean.protocol.constants import RORG
try:
import queue
except ImportError:
import Queue as queue
def send_command(destination, output_value):
global communicator
communicator.send(
RadioPacket.create(rorg=RORG.VLD, rorg_func=0x01, rorg_type=0x01, destination=destination, sender=communicator.base_id, command=1, IO=0x1E, OV=output_value)
)
def turn_on(destination):
send_command(destination, 100)
def turn_off(destination):
send_command(destination, 0)
communicator = SerialCommunicator()
communicator.start()
print('The Base ID of your module is %s.' % enocean.utils.to_hex_string(communicator.base_id))
# Example of turning switches on and off
turn_on([0x01, 0x94, 0xB9, 0x46])
# Needs a bit of sleep in between, working too fast :S
time.sleep(0.1)
turn_on([0x01, 0x94, 0xE3, 0xB9])
time.sleep(1)
turn_off([0x01, 0x94, 0xB9, 0x46])
time.sleep(0.1)
turn_off([0x01, 0x94, 0xE3, 0xB9])
print('Press and hold the teach-in button on the plug now, till it starts turning itself off and on (about 10 seconds or so...)')
devices_learned = []
# endless loop receiving radio packets
while communicator.is_alive():
try:
# Loop to empty the queue...
packet = communicator.receive.get(block=True, timeout=1)
if isinstance(packet, UTETeachInPacket):
print('New device learned! The ID is %s.' % (packet.sender_hex))
devices_learned.append(packet.sender)
except queue.Empty:
continue
except KeyboardInterrupt:
break
except Exception:
traceback.print_exc(file=sys.stdout)
break
print('Devices learned during this session: %s' % (', '.join([enocean.utils.to_hex_string(x) for x in devices_learned])))
if communicator.is_alive():
communicator.stop()
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from enocean.consolelogger import init_logging
from enocean.communicators.serialcommunicator import SerialCommunicator
from enocean.communicators.utils import send_to_tcp_socket
import sys
import traceback
try:
import queue
except ImportError:
import Queue as queue
init_logging()
communicator = SerialCommunicator()
communicator.start()
while communicator.is_alive():
try:
# Loop to empty the queue...
packet = communicator.receive.get(block=True, timeout=1)
send_to_tcp_socket('localhost', 9637, packet)
except queue.Empty:
continue
except KeyboardInterrupt:
break
except Exception:
traceback.print_exc(file=sys.stdout)
break
if communicator.is_alive():
communicator.stop()
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from enocean.consolelogger import init_logging
from enocean.communicators.tcpcommunicator import TCPCommunicator
from enocean.protocol.constants import PACKET, RORG
import sys
import traceback
try:
import queue
except ImportError:
import Queue as queue
init_logging()
communicator = TCPCommunicator()
communicator.start()
while communicator.is_alive():
try:
# Loop to empty the queue...
packet = communicator.receive.get(block=True, timeout=1)
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.BS4:
for k in packet.parse_eep(0x02, 0x05):
print('%s: %s' % (k, packet.parsed[k]))
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.BS1:
for k in packet.parse_eep(0x00, 0x01):
print('%s: %s' % (k, packet.parsed[k]))
if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.RPS:
for k in packet.parse_eep(0x02, 0x04):
print('%s: %s' % (k, packet.parsed[k]))
except queue.Empty:
continue
except KeyboardInterrupt:
break
except Exception:
traceback.print_exc(file=sys.stdout)
break
if communicator.is_alive():
communicator.stop()