From 0f4ad4b2788244a2208bbd67d1bcd0522fb0b88d Mon Sep 17 00:00:00 2001 From: iwahdan88 Date: Thu, 11 Jul 2019 11:58:08 +0200 Subject: [PATCH] Updated wlan with promoscious mode example --- content/firmwareapi/pycom/network/wlan.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/content/firmwareapi/pycom/network/wlan.md b/content/firmwareapi/pycom/network/wlan.md index 79fa317..b561e29 100644 --- a/content/firmwareapi/pycom/network/wlan.md +++ b/content/firmwareapi/pycom/network/wlan.md @@ -291,6 +291,29 @@ Note: * Promiscuous mode should be enabled for Wifi packets types Events to be triggered * for changing wifi channel via `wlan.channel()` promiscuous mode should be enabled. +Example using promoscious mode: + +``` +from network import WLAN +import ubinascii + +def pack_cb(pack): + mac = bytearray(6) + pk = wlan.wifi_packet() + control = pk.data[0] + subtype = (0xF0 & control) >> 4 + type = 0x0C & control + #print("Control:{}, subtype:{}, type:{}".format(control, subtype, type)) + if subtype == 4: + for i in range (0,6): + mac[i] = pk.data[10 + i] + print ("Wifi Node with MAC: {}".format(ubinascii.hexlify(mac))) + +wlan = WLAN(mode=WLAN.STA, antenna=WLAN.EXT_ANT) +wlan.callback(trigger=WLAN.EVENT_PKT_MGMT, handler=pack_cb) +wlan.promiscuous(True) +``` + ### wlan.events() This function will return an integer object as mask for triggered events.