Esempio n. 1
0
def get_ip_address():
    """
    Returns the IP address associated to the device.
    """
    try:
        return wifi.link_info()[0]
    except Exception as e:
        print("Could not get IP address. Returning empty string.")
        return ""
Esempio n. 2
0
def connectWifi(SSID, PASSWORD):
    print("Connecting to Wi-Fi router...")
    
    for i in range(0,5):
    try:
        wifi.link(SSID,wifi.WIFI_WPA2,PASSWORD)
        break
    except Exception as e:
        print("Error: ", e)
    else:
        print("Cannot connect.")
        while True:
            sleep(1000)
            


def on_switch():
    digitalWrite(D5,LOW)
    print("ON")

def off_switch():
    digitalWrite(D5,HIGH)
    print("OFF")
    




# Intialize APP
pinMode(RELAY_PIN, OUTPUT)
wifi_driver.auto_init()
connectWifi(SSID,PASSWORD)
info = wifi.link_info()
print("Connected to WiFI IP:",info[0])

zapp = zerynthapp.ZerynthApp(UID, TOKEN, log=True)
zapp.on("on_switch", on_switch)
zapp.on("off_switch",off_switch)
zapp.run()

while True:
    try:
        sleep(1000)
    except Exception as e:
        print("Error: ",e)
Esempio n. 3
0
from wireless import wifi

streams.serial()

# init the cc3000 drivers: works on arduino compatibles and Particle Core.
# The driver automatically registers itself to the wifi interface
# so the wifi module can use the cc3000 without your intervention 
cc3000.auto_init()

# use the wifi interface to link to the Access Point
# change network name, security and password as needed
print("Establishing Link...")
try:
    wifi.link("Network-Name",wifi.WIFI_WPA2,"Wifi-Password")
    # get our ip
    myip = wifi.link_info()[0]
    # convert myip to a tuple with the socket.ip_to_tuple function
    # "x.y.z.w" becomes (x,y,z,w)
    ip_tuple = socket.ip_to_tuple(myip)
    # generate a broadcast address to port 9999
    # (it's ok and easier to generate it as a 5 number tuple)
    broadcast = (ip_tuple[0],ip_tuple[1],ip_tuple[2],255,9999)
    print(myip,ip_tuple,broadcast)
    # create an UDP socket and bind it to port 9999
    sock = socket.socket(type=socket.SOCK_DGRAM)
    sock.bind(9999)
except Exception as e:
    print("ooops, something wrong while linking :(", e)
    while True:
        sleep(1000)
                sleep(1000)


def on_switch():
    digitalWrite(D5, LOW)
    print("ON")


def off_switch():
    digitalWrite(D5, HIGH)
    print("OFF")


# Intialize APP
pinMode(RELAY_PIN, OUTPUT)
wifi_driver.auto_init()
connectWifi(SSID, PASSWORD)
info = wifi.link_info()
print("Connected to WiFI IP:", info[0])

zapp = zerynthapp.ZerynthApp(UID, TOKEN, log=True)
zapp.on("on_switch", on_switch)
zapp.on("off_switch", off_switch)
zapp.run()

while True:
    try:
        sleep(1000)
    except Exception as e:
        print("Error: ", e)
Esempio n. 5
0
from wireless import wifi

streams.serial()

# init the cc3000 drivers: works on arduino compatibles and Particle Core.
# The driver automatically registers itself to the wifi interface
# so the wifi module can use the cc3000 without your intervention
cc3000.auto_init()

# use the wifi interface to link to the Access Point
# change network name, security and password as needed
print("Establishing Link...")
try:
    wifi.link("Network-Name", wifi.WIFI_WPA2, "Wifi-Password")
    # get our ip
    myip = wifi.link_info()[0]
    # convert myip to a tuple with the socket.ip_to_tuple function
    # "x.y.z.w" becomes (x,y,z,w)
    ip_tuple = socket.ip_to_tuple(myip)
    # generate a broadcast address to port 9999
    # (it's ok and easier to generate it as a 5 number tuple)
    broadcast = (ip_tuple[0], ip_tuple[1], ip_tuple[2], 255, 9999)
    print(myip, ip_tuple, broadcast)
    # create an UDP socket and bind it to port 9999
    sock = socket.socket(type=socket.SOCK_DGRAM)
    sock.bind(9999)
except Exception as e:
    print("ooops, something wrong while linking :(", e)
    while True:
        sleep(1000)
Esempio n. 6
0
# Viper Example Code

# import streams & socket
import streams
import socket

# import the broadcom 43362 wifi driver
from drivers.wifi.bcm43362 import bcm43362 as bcm
# import the wifi interface
from wireless import wifi

streams.serial()

# init the broadcom driver: works on the Photon and Broadcom based boards
# The driver automatically registers itself to the wifi interface
# so the wifi module can use the Broadcom chip without your intervention
bcm.auto_init()

print("establishing link...")
try:
    wifi.link("", wifi.WIFI_WPA2, "")
except Exception as e:
    print ("oops, something went wrong while linking :(", e)
    sleep(5000)

print ("Linked!")

info = wifi.link_info()
print("My IP is: ", info[0])
def printNetworkParametes():
    networkInfo = wifi.link_info()
    print("IP: ", networkInfo[0])
    print("Netmask: ", networkInfo[1])
    print("Gateway: ", networkInfo[2])
    print("DNS: ", networkInfo[3])
Esempio n. 8
0
                                sleep(100)
                        else:
                            mcu.reset()
                        page = page + 1
                        sfw.kick()
                    sleep(5000)
                    wifi.unlink()
                except Exception as e:
                    print("Error!", e)
                    sleep(100)

            except Exception as e:
                print("Error while sniffing:", e)


# Initialize board
init()
mac_addr = ':'.join([hex(b, prefix='') for b in wifi.link_info()[4]])
print('Current MAC addr', mac_addr)
# Perform initial channel analysis (1000 ms of sleep per iterations, 2 iterations)
scan_for_active_channels(1000, 2)
# Initiate timer
t.start()
# Scan for packets (100 ms of sleep per iteration, 20 iterations,
# channels are considered active if their activity percentage is
# greater than or equal to 1%, scanning channel activity every
# 60000 ms = 60 s)
get_packets(1000, 5, 0.01, 60000)

print("Ended")