Exemplo n.º 1
0
def descubrir_red():
    global dispositivos
    dispositivos.clear()
    for device in xbee.discover():
        dis = {
            "name": device["node_id"],
            "addr": device["sender_eui64"],
            "rssi": device["rssi"]
        }
        dispositivos[device["node_id"]] = dis
def discover(next_ms):                      # discover関数の定義
    if time.ticks_ms() < next_ms:           # 現在時刻が次回の実行時刻に満たない時
        return next_ms                      # 処理を中止
    disc_devs = xbee.discover()             # デバイスを検索し、結果をdisc_devsへ代入
    for dev in disc_devs:                   # 個々のデバイスの処理
        addr = str(binascii.hexlify(dev['sender_eui64']).decode('utf-8'))
        type = DEV_TYPES[ dev['node_type'] ]
        if addr not in devs:                # 過去に発見されていないデバイス発見時
            devs.append(addr)               # 配列に送信元アドレスを追加
            addr=addr[:8] + ' ' + addr[8:]  # 送信元アドレスを表示用(8+8文字)に分離
            print('found',addr,type)        # 発見したデバイスを表示する
    next_ms = time.ticks_ms() + 6000        # 次回の実行は6秒後
    return next_ms
Exemplo n.º 3
0
def find_device(node_id):
    """
    Finds the XBee device with the given node identifier in the network and
    returns it.

    :param node_id: Node identifier of the XBee device to find.

    :return: The XBee device with the given node identifier or ``None`` if it
        could not be found.
    """
    for dev in xbee.discover():
        if dev['node_id'] == node_id:
            return dev
    return None
Exemplo n.º 4
0
def find_gateway(retries=3):
    for i in range(1, retries + 1):
        print("Searching destination %s %d/%d" % (DEST_NODE_ID, i, retries))

        try:
            devices = xbee.discover()
        except OSError:
            devices = []

        for dev in devices:
            if dev.get('node_id', None) == DEST_NODE_ID:
                gateway = dev.get('sender_eui64', None)
                return gateway if gateway else dev.get('sender_nwk', None)
        time.sleep_ms(1500)

    return None
Exemplo n.º 5
0
 def LocateDevice(self):
     for dev in xbee.discover():
         if dev['node_id'] in self.device_dict:
             self.DisplayData(dev)
Exemplo n.º 6
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import xbee


print(" +-------------------------------------------+")
print(" | XBee MicroPython Network Discovery Sample |")
print(" +-------------------------------------------+\n")

print("Discovering network devices...\n")

# Discover the network devices and print their basic information.
for device in xbee.discover():
    addr64 = device['sender_eui64']
    node_id = device['node_id']
    rssi = device['rssi']

    print("New discovered device:\n"
          "  - 64-bit address: %s\n"
          "  - Node identifier: %s\n"
          "  - RSSI: %d\n"
          % (''.join('{:02x}'.format(x).upper() for x in addr64), node_id, rssi))

print("Network discovery finished")
Exemplo n.º 7
0
def descubrir_red():
    global dispositivos
    for device in xbee.discover():
        if device["node_type"] is 0:
            dispositivos = {"coordinador": device["sender_eui64"]}
Exemplo n.º 8
0
	return xbee.atcmd("AI")  # If the value of AI is non zero, the module is not connected to a network
print("Forming a new 802.15.4 network as a coordinator...")
xbee.atcmd("NI", "Coordinator")
network_settings = {"CE": 1, "A2": 4, "CH": 0x13, "MY": 0xFFFF, "ID": 0x3332, "EE": 0}
for command, value in network_settings.items():
	xbee.atcmd(command, value)
xbee.atcmd("AC")  # Apply changes
time.sleep(1)
while network_status() != 0:
	time.sleep(0.1)
print("Network Established\n")

print("Waiting for a remote node to join...")
node_list = []
while len(node_list) == 0: # Perform a network discovery until the remote joins
	node_list = list(xbee.discover())
print("Remote node found, transmitting data")

for node in node_list:
	dest_addr = node['sender_eui64'] # using 64-bit addressing
	dest_node_id = node['node_id']
	payload_data = "Hello, " + dest_node_id

	xbee.transmit(dest_addr, payload_data)

# Start the receive loop
print("Receiving data...")
print("Hit CTRL+C to cancel")
while True:
	p = xbee.receive()
	if p: