import os
import time
#import digi.xbee.devices
from digi.xbee.devices import XBeeDevice
from digi.xbee.devices import RemoteXBeeDevice
from digi.xbee.models.address import XBee64BitAddress
Tx = XBeeDevice("COM11", 9600)  # COM port of the Receiver
Rx = RemoteXBeeDevice(Tx, XBee64BitAddress.from_hex_string("0013A20041630A6B"))
received_ack = True
Tx.open()

#def message_received(data):
xbee_message = Tx.read_data()


#if xbee_message.data == "Acknowledgment":
#               print "Acknowledgment received"
#               global recieved_ack
#               recieved_ack = True
def my_data_received_callback(xbee_message):
    address = xbee_message.remote_device.get_64bit_addr()
    data = xbee_message.data.decode("utf8")
    if data == "Transmitting":
        print("Received data from %s: %s" % (address, data))
        global received_ack
        received_ack = True


# Add the callback.
Tx.add_data_received_callback(my_data_received_callback)
Beispiel #2
0
    def at_response_received_cb(self, response):
        """
        Callback to deal with AT command responses and update the
        corresponding node. Only for internal use.

        Args:
            response (:class: `.XBeeAPIPacket`): The received API packet.
        """
        f_type = response.get_frame_type()
        if f_type not in (ApiFrameType.AT_COMMAND_RESPONSE,
                          ApiFrameType.REMOTE_AT_COMMAND_RESPONSE):
            return

        node = self.__xbee
        # Get remote node in case of a remote at command
        if (f_type == ApiFrameType.REMOTE_AT_COMMAND_RESPONSE
                and XBee64BitAddress.is_known_node_addr(response.x64bit_source_addr)):
            node = self.__xbee.get_network().get_device_by_64(response.x64bit_source_addr)

        if not node:
            return

        key = str(node.get_64bit_addr())
        requests = self._at_cmds_sent.get(key, {})
        req = requests.pop(response.frame_id, None)

        if not req or response.status != ATCommandStatus.OK:
            return

        def is_req_apply(at_req):
            fr_type = at_req.get_frame_type()
            return (at_req.command.upper() == ATStringCommand.AC.command
                    or fr_type == ApiFrameType.AT_COMMAND
                    or (fr_type == ApiFrameType.REMOTE_AT_COMMAND_REQUEST
                        and at_req.transmit_options & RemoteATCmdOptions.APPLY_CHANGES.value))

        def is_node_info_param(at_pkt):
            at_cmd = at_pkt.command.upper()
            return at_cmd in (ATStringCommand.NI.command,
                              ATStringCommand.MY.command)

        def is_port_param(at_pkt):
            at_cmd = at_pkt.command.upper()
            return at_cmd in (ATStringCommand.AP.command,
                              ATStringCommand.BD.command,
                              ATStringCommand.NB.command,
                              ATStringCommand.SB.command)

        apply = is_req_apply(req)
        if apply:
            if key not in self._future_apply:
                self._future_apply[key] = {}

            node_fut_apply = self._future_apply.get(key, {})
            node_fut_apply.pop(req.command.upper(), None)
            for key, value in list(node_fut_apply.items()):
                self._refresh_if_cached(node, key, value, apply=True)

        if req.parameter and (is_port_param(req) or is_node_info_param(req)):
            self._refresh_if_cached(node, req.command.upper(), req.parameter,
                                    apply=apply)
    #LOOK FOR XBEE
    context = pyudev.Context()
    port_name = '/dev/ttyUSB0'

    for device in context.list_devices(subsystem='tty'):
        if 'ID_VENDOR' in device and device['ID_VENDOR'] == 'FTDI':
            port_name = device['DEVNAME']

    my_address = int(args[0])

    #Connect to XBEE
    device = XBeeDevice(port_name, baud)
    device.open()

    dest_address = XBee64BitAddress.from_hex_string("000000000000FFFF")
    device.set_dest_address(dest_address)

    device.set_pan_id(bytearray.fromhex(opts.pan_id))

    #cmd = 'AP2,'

    device.set_parameter("AP", bytearray.fromhex("02"))
    if (opts.coordinator):
        device.set_parameter("CE", bytearray.fromhex("01"))
    else:
        device.set_parameter("CE", bytearray.fromhex("00"))
    #cmd += 'CE1,' #API mode 2, and enable coordinator

    device.set_parameter("MY", utils.int_to_bytes(my_address))
    device.set_parameter("NI", bytearray(opts.name, 'utf8'))
def main(Node_Address):

    NodeAddress = XBee64BitAddress.from_hex_string(Node_Address)

    print(" +-------------------------------------------------------+")
    print(" |  Write Remote XBee (" + Node_Address + ") parameters      |")
    print(" +---------------------------------------------------- --+\n")

    local_device = XBeeDevice(PORT, BAUD_RATE)
    local_device.open()
    remote_device = RemoteZigBeeDevice(local_device, NodeAddress)

    try:

        # Get Hardware Models with extended DIO (P5 to P9)
        Hardware_Extended = read_sys_config.ReadHardwareVersionWhithP5ToP9PinsFromFile(
        )
        HV = utils.hex_to_string(remote_device.get_parameter("HV"))
        # Set file name source of the params
        print("0013A200416299FE")
        read_node_config_file.set_path_to_file(Node_Address)
        #No se puede modificar la PAN ID vía RF porque se pierde conexión

        print(read_node_config_file.ReadScanChannelsFromFile(Node_Address))
        remote_device.set_parameter(
            "SC",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadScanChannelsFromFile(Node_Address)))
        remote_device.set_parameter(
            "SD",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadScanDurationFromFile(Node_Address)))
        remote_device.set_parameter(
            "ZS",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadZigBeeStackProfileFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "NJ",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadNodeJoinTimeFromFile(Node_Address)))
        remote_device.set_parameter(
            "NW",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadNetworkWatchdogTimeoutFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "JV",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadChannelVerificationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "JN",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadJoinNotificationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "CE",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadCoordinatorEnableFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "DO",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDeviceOptionsFromFile(Node_Address)))
        remote_device.set_parameter(
            "DC",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDeviceControlsFromFile(
                    Node_Address)))
        # Addressing
        remote_device.set_parameter(
            "DH",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDestinationAddressHighFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "DL",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDestinationAddressLowFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "NI",
            bytearray(
                read_node_config_file.ReadNodeIdentifierFromFile(Node_Address),
                'utf8'))
        remote_device.set_parameter(
            "NH",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadMaximumHopsFromFile(Node_Address)))
        remote_device.set_parameter(
            "BH",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadBroadcastRadiusFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "AR",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadManyToOneRouteBroadcastTimeFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "DD",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDeviceTypeIdentifierFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "NT",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadNodeDiscoveryBackoffFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "NO",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadNodeDiscoveryOptionsFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "CR",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadPanConflictThresholdFromFile(
                    Node_Address)))
        # ZigBee Addressing
        remote_device.set_parameter(
            "SE",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadZigBeeSourceEndPointFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "DE",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadZigBeeDestinationEndpointFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "CI",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadZigBeeClusterIDFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "TO",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadTransmitOptionsFromFile(
                    Node_Address)))
        # RF Interfacing
        remote_device.set_parameter(
            "PL",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadTxPowerLevelFromFile(Node_Address)))
        remote_device.set_parameter(
            "PM",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadPowerModeFromFile(Node_Address)))
        # Security
        remote_device.set_parameter(
            "EE",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadEncryptionEnableFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "EO",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadEncryptionOptionsFromFile(
                    Node_Address)))
        # No se pueden cambiar las keys vía RF

        # Serial Interfacing
        remote_device.set_parameter(
            "BD",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadBaudRateFromFile(Node_Address)))
        remote_device.set_parameter(
            "NB",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadParityFromFile(Node_Address)))
        remote_device.set_parameter(
            "SB",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadStopBitsFromFile(Node_Address)))
        remote_device.set_parameter(
            "RO",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadPacketizationTimeoutFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D6",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO6ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D7",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO7ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "AP",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadApiEnableFromFile(Node_Address)))
        remote_device.set_parameter(
            "AO",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadApiOutputModeFromFile(Node_Address)))
        # AT Command Options
        remote_device.set_parameter(
            "CT",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadATCommandModeTimeoutFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "GT",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadGuardTimesFromFile(Node_Address)))
        remote_device.set_parameter(
            "CC",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadCommandSequenceCharacterFromFile(
                    Node_Address)))
        # Sleep Modes
        remote_device.set_parameter(
            "SP",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadCyclicSleepPeriodFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "SN",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadNumberOfCyclicSleepPeriodsFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "SM",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadSleepModeFromFile(Node_Address)))
        remote_device.set_parameter(
            "ST",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadTimeBeforeSleepFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "SO",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadSleepOptionsFromFile(Node_Address)))
        remote_device.set_parameter(
            "WH",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadWakeHostFromFile(Node_Address)))
        remote_device.set_parameter(
            "PO",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadPollRateFromFile(Node_Address)))
        # I/O Settings
        remote_device.set_parameter(
            "D0",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO0AD0ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D1",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO1AD1ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D2",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO2AD2ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D3",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO3AD3ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D4",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO4ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D5",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO5ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D8",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO8ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "D9",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO9ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "P0",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO10ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "P1",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO11ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "P2",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO12ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "P3",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO13ConfigurationFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "P4",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDIO14ConfigurationFromFile(
                    Node_Address)))
        if HV == Hardware_Extended:
            remote_device.set_parameter(
                "P5",
                utils.hex_string_to_bytes(
                    read_node_config_file.ReadDIO15ConfigurationFromFile(
                        Node_Address)))
            remote_device.set_parameter(
                "P6",
                utils.hex_string_to_bytes(
                    read_node_config_file.ReadDIO16ConfigurationFromFile(
                        Node_Address)))
            remote_device.set_parameter(
                "P7",
                utils.hex_string_to_bytes(
                    read_node_config_file.ReadDIO17ConfigurationFromFile(
                        Node_Address)))
            remote_device.set_parameter(
                "P8",
                utils.hex_string_to_bytes(
                    read_node_config_file.ReadDIO18ConfigurationFromFile(
                        Node_Address)))
            remote_device.set_parameter(
                "P9",
                utils.hex_string_to_bytes(
                    read_node_config_file.ReadDIO19ConfigurationFromFile(
                        Node_Address)))
        remote_device.set_parameter(
            "PR",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadPullUpResistorEnableFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "PD",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadPullUpDownDirectionFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "LT",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadAssociatedLedBlinkTimeFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "RP",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadRssiPwmTimerFromFile(Node_Address)))
        # I/O Sampling
        remote_device.set_parameter(
            "IR",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadIOSamplingRateFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "IC",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadDigitalIOChangeDetectionFromFile(
                    Node_Address)))
        remote_device.set_parameter(
            "V+",
            utils.hex_string_to_bytes(
                read_node_config_file.ReadSupplyVoltageHihgThresholdFromFile(
                    Node_Address)))

        # Make params permanent
        remote_device.write_changes()  # make changes permanet"""

        # print parameters
        log = "  Success!! All Parameters Were Written  \n\n"
        print("  Success!! All Parameters Were Written  ")

    except:
        log = "  Sorry, an error has happened during writting operation\n"
        if local_device.is_open():
            local_device.close()
        pass

    finally:
        if local_device is not None and local_device.is_open():
            local_device.close()

    return log
 def remote_device(self):
     return RemoteXBeeDevice(
         self.device, XBee64BitAddress.from_hex_string(self.coordenador))
Beispiel #6
0
    def create_packet(raw, operating_mode):
        """
        Override method.

        Returns:
            :class:`.RouteInformationPacket`.

        Raises:
            InvalidPacketException: If the bytearray length is less than 46.
                (start delim. + length (2 bytes) + frame type + src_event
                 + length + timestamp (4 bytes) + ack timeout count
                 + tx blocked count + reserved + dest addr (8 bytes)
                 + src addr (8 bytes) + responder addr (8 bytes)
                 + succesor addr (8 bytes) + checksum = 46 bytes).
            InvalidPacketException: If the length field of `raw` is different
                from its real length. (length field: bytes 1 and 3)
            InvalidPacketException: If the first byte of 'raw' is not the
                header byte. See :class:`.SpecialByte`.
            InvalidPacketException: If the calculated checksum is different
                from the checksum field value (last byte).
            InvalidPacketException: If the frame type is not
                :attr:`.ApiFrameType.DIGIMESH_ROUTE_INFORMATION`.
            InvalidPacketException: If the internal length byte of the rest
                of the frame (without the checksum) is different from its real
                length.
            InvalidOperatingModeException: If `operating_mode` is not
                supported.

        .. seealso::
           | :meth:`.XBeePacket.create_packet`
           | :meth:`.XBeeAPIPacket._check_api_packet`
        """
        if operating_mode not in (OperatingMode.ESCAPED_API_MODE,
                                  OperatingMode.API_MODE):
            raise InvalidOperatingModeException(operating_mode.name +
                                                " is not supported.")

        XBeeAPIPacket._check_api_packet(
            raw, min_length=RouteInformationPacket.__MIN_PACKET_LENGTH)

        if raw[3] != ApiFrameType.DIGIMESH_ROUTE_INFORMATION.code:
            raise InvalidPacketException(
                "This packet is not a Route Information packet.")

        # 7: frame len starting from this byte (index 5) and without the checksum
        if raw[5] != len(raw) - 7:
            raise InvalidPacketException(
                "Length does not match with the data length")

        additional_data = []
        if len(raw) > RouteInformationPacket.__MIN_PACKET_LENGTH:
            additional_data = raw[45:]
        packet = RouteInformationPacket(raw[4], utils.bytes_to_int(raw[6:10]),
                                        raw[10], raw[11],
                                        XBee64BitAddress(raw[13:21]),
                                        XBee64BitAddress(raw[21:29]),
                                        XBee64BitAddress(raw[29:37]),
                                        XBee64BitAddress(raw[37:45]),
                                        additional_data)
        packet._reserved = raw[12]

        return packet
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import random
import string
from digi.xbee.devices import XBeeDevice, RemoteXBeeDevice
from digi.xbee.models.address import XBee64BitAddress
from digi.xbee.util.utils import hex_to_string

# TODO: Replace with the serial port where your local module is connected to.
PORT = "COM1"
# TODO: Replace with the baud rate of your local module.
BAUD_RATE = 9600
# TODO: Replace with the 64-bit address of the remote device.
REMOTE_DEVICE_ADDRESS = XBee64BitAddress.from_hex_string("0013A20040D47B73")


def main():

    print(" +---------------------------------+")
    print(" | Get and Set Params Local/Remote |")
    print(" +---------------------------------+\n")

    local_xbee = XBeeDevice(PORT, BAUD_RATE)

    try:
        local_xbee.open()
        remote_xbee = RemoteXBeeDevice(local_xbee,
                                       x64bit_addr=REMOTE_DEVICE_ADDRESS)
import tkinter.messagebox
from digi.xbee.devices import XBeeDevice
from digi.xbee.devices import RemoteXBeeDevice
from digi.xbee.models.address import XBee64BitAddress
from digi.xbee.reader import XBeeMessage
import time
import os
from datetime import *
from tkcalendar import Calendar
import sqlite3

os.system('sudo chmod 777 /dev/ttyUSB0')

coordenador = XBeeDevice('/dev/ttyUSB0', 9600)
router1 = RemoteXBeeDevice(
    coordenador, XBee64BitAddress.from_hex_string("0013A200409BAF15"))
router2 = RemoteXBeeDevice(
    coordenador, XBee64BitAddress.from_hex_string("0013A200409BAF12"))

print('Done')
try:
    coordenador.open()

except:
    print('\n\nERRO NA COMUNICAÇÃO!\n\n')
    exit()

DATABASE_EXISTS = False

if (os.path.isfile('agendamento.db') == False):
    DATABASE_EXISTS = False
def main():
    print(" +----------------------------------------------------------+")
    print(" | XBee Python Library Network modifications Devices Sample |")
    print(" +----------------------------------------------------------+\n")

    xbee_network = None

    xbee = XBeeDevice(PORT, BAUD_RATE)

    try:
        xbee.open()

        xbee_network = xbee.get_network()

        xbee_network.set_discovery_timeout(15)  # 15 seconds.

        xbee_network.add_discovery_process_finished_callback(
            callback_discovery_finished)

        xbee_network.add_network_modified_callback(cb_network_modified)

        print("* Discover remote XBee devices...")

        xbee_network.start_discovery_process()

        while xbee_network.is_discovery_running():
            time.sleep(1)

        print_nodes(xbee_network)

        print("\n* Manually add a new remote XBee device...")
        remote = RemoteXBeeDevice(
            xbee,
            x64bit_addr=XBee64BitAddress.from_hex_string("1234567890ABCDEF"),
            node_id="manually_added")
        xbee_network.add_remote(remote)

        print_nodes(xbee_network)

        time.sleep(1)

        print("\n* Update the last added remote XBee device...")
        remote = RemoteXBeeDevice(xbee,
                                  x64bit_addr=remote.get_64bit_addr(),
                                  node_id="updated_node")
        xbee_network.add_remote(remote)

        print_nodes(xbee_network)

        time.sleep(1)

        print("\n* Manually remove a remote XBee device...")
        xbee_network.remove_device(remote)

        print_nodes(xbee_network)

        time.sleep(1)

        print("\n* Clear network...")
        xbee_network.clear()

        print_nodes(xbee_network)

    finally:
        if xbee_network is not None:
            xbee_network.del_discovery_process_finished_callback(
                callback_discovery_finished)
            xbee_network.del_network_modified_callback(cb_network_modified)

        if xbee is not None and xbee.is_open():
            xbee.close()
Beispiel #10
0
def send_data():
    global count
    count = count + 1
    remote_device = RemoteXBeeDevice(
        my_device, XBee64BitAddress.from_hex_string(DRONE_ID))
    my_device.send_data(remote_device, DATA_TO_SEND + str(count))
import random
import os
from digi.xbee.devices import XBeeDevice
from digi.xbee.devices import RemoteXBeeDevice
from digi.xbee.models.address import XBee64BitAddress
from digi.xbee.models.status import TransmitStatus
import tkinter as tk
from tkinter import *
from tkinter import font
import sys
import datetime
import time

Tx = XBeeDevice("COM5", 9600)
Rx1 = RemoteXBeeDevice(Tx,
                       XBee64BitAddress.from_hex_string("0013A200416411DF"))
Rx2 = RemoteXBeeDevice(Tx,
                       XBee64BitAddress.from_hex_string("0013A20041630A75"))
Rx3 = RemoteXBeeDevice(Tx,
                       XBee64BitAddress.from_hex_string("0013A200418B68F8"))
Tx.open()

window = tk.Tk()

window.title('LMU AirLions')
#You can set the geometry attribute to change the root windows size
window.geometry("1000x1000")  #You want the size of the app to be 500x500

back = tk.Frame(window, bg='black')
window.configure(background='black')
        while arduino.inWaiting() > 0:
            texto = arduino.readline()
            texto = texto.decode("utf8")
            texto = texto[:-2]
            print("\nDatos del sensor: ", texto, "\n")
            # Con 21 para "TEMP-xx:SND-xx:LUZ-xx"
            if len(texto) == 21:
                x = 1
    arduino.close()

    # Datos recogidos
    time.sleep(1)
    data = "Recogidos"
    data = data.encode("utf8")
    coord = RemoteXBeeDevice(
        device, XBee64BitAddress.from_hex_string("0013A20040C53D49"))
    device.send_data(coord, data)

    #Leer
    mens = None
    print("\nEsperando mi turno...\n")
    while mens == None:
        # Recivo de coordinador
        mens = device.read_data_from(coord)
        time.sleep(0.5)

    print("\nEnviando datos solicitados\n")
    data = texto.encode("utf8")
    # Envio a coordinador
    device.send_data(coord, data)
    print("Datos enviados con exito!\n")
Beispiel #13
0
        def data_receive_callback(xbee_message):
            data = xbee_message.data
            command = [
                int.from_bytes(data[:2], "big"),
                int.from_bytes(data[2:3], "big"),
                int.from_bytes(data[3:4], "big"),
                int.from_bytes(data[5:6], "big"),
                int.from_bytes(data[6:7], "big")
            ]
            print("Data[0]:", command[0])
            print("Data[1]:", command[1])
            print("Data[2]:", command[2])
            print("Data[3]:", command[3])
            print("Data[4]:", command[4])
            temperature, pressure, humidity = readBME280All()

            if command[1] == 3:
                if command[2] == 1:
                    if command[0] == 1:
                        #teste="teste2"
                        remote_device = RemoteXBeeDevice(
                            device,
                            XBee64BitAddress.from_hex_string(
                                "0000000000000000"))
                        print("Temp      = {0:0.3f} Deg C", temperature,
                              float.hex(temperature),
                              float.fromhex(float.hex(temperature)))
                        # Send data using the remote object.
                        print("", float.fromhex(float.hex(temperature)))
                        print("" + float.hex(temperature))
                        device.send_data(remote_device,
                                         '' + float.hex(temperature))

                    if command[0] == 2:
                        print("Press      = {0:0.3f}", pressure,
                              float.hex(pressure),
                              float.fromhex(float.hex(pressure)))
                        remote_device = RemoteXBeeDevice(
                            device,
                            XBee64BitAddress.from_hex_string(
                                "0000000000000000"))
                        # Send data using the remote object.
                        print("", float.fromhex(float.hex(pressure)))
                        print("" + float.hex(pressure))
                        device.send_data(remote_device,
                                         '' + float.hex(pressure))
                    if command[0] == 3:
                        print("Humity      = {0:0.3f} %", humidity,
                              float.hex(humidity),
                              float.fromhex(float.hex(humidity)))
                        remote_device = RemoteXBeeDevice(
                            device,
                            XBee64BitAddress.from_hex_string(
                                "0000000000000000"))
                        # Send data using the remote object.
                        print("", float.fromhex(float.hex(humidity)))
                        print("" + float.hex(humidity))
                        device.send_data(remote_device,
                                         '' + float.hex(humidity))
                    #if command[0]==4:
            if command[1] == 1:
                if command[2] == 2:
                    if command[4] == 1:
                        print("Meta-TEDS")