m0e 3 years ago
commit
fa9ad04200
8 changed files with 159 additions and 0 deletions
  1. BIN
      MultiFrame_1_1_1_1.zip
  2. 1 0
      WiPy
  3. 15 0
      blueLE-test.py
  4. BIN
      lopy_v01_3_pinout_rc.png
  5. 64 0
      main-lora-868.py
  6. 40 0
      main.py
  7. 39 0
      main.py333
  8. BIN
      witty-pinout.jpg

BIN
MultiFrame_1_1_1_1.zip


+ 1 - 0
WiPy

@@ -0,0 +1 @@
+Subproject commit f90cd0e80163df1c1a246dc872cecadf5397d50b

+ 15 - 0
blueLE-test.py

@@ -0,0 +1,15 @@
+from network import Bluetooth
+
+bluetooth = Bluetooth()
+bluetooth.set_advertisement(name='LoPy', service_uuid=b'1234567890123456')
+
+def conn_cb (bt_o):
+    events = bt_o.events()   # this method returns the flags and clears the internal registry
+    if events & Bluetooth.CLIENT_CONNECTED:
+        print("Client connected")
+    elif events & Bluetooth.CLIENT_DISCONNECTED:
+        print("Client disconnected")
+
+bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)
+
+bluetooth.advertise(True)

BIN
lopy_v01_3_pinout_rc.png


+ 64 - 0
main-lora-868.py

@@ -0,0 +1,64 @@
+import os
+import machine
+
+uart = machine.UART(0, 115200)
+os.dupterm(uart)
+
+known_nets = {
+    'UpUpUp': {'pwd': 't4k4tuk4l4nd2', 'wlan_config':  ('192.168.2.115', '255.255.255.0', '192.168.2.1', '192.168.2.1')},
+    'Vidit-Fabrik': {'pwd': '%m1n!5NK=$', 'wlan_config':  ('192.168.0.115', '255.255.255.0', '192.168.0.1', '192.168.0.1')}, # (ip, subnet_mask, gateway, DNS_server)
+}
+
+if machine.reset_cause() != machine.SOFT_RESET:
+    from network import WLAN
+    wl = WLAN()
+    wl.mode(WLAN.STA)
+    original_ssid = wl.ssid()
+    original_auth = wl.auth()
+
+    print("Scanning for known wifi nets")
+    available_nets = wl.scan()
+    nets = frozenset([e.ssid for e in available_nets])
+
+    known_nets_names = frozenset([key for key in known_nets])
+    net_to_use = list(nets & known_nets_names)
+    try:
+        net_to_use = net_to_use[0]
+        net_properties = known_nets[net_to_use]
+        pwd = net_properties['pwd']
+        sec = [e.sec for e in available_nets if e.ssid == net_to_use][0]
+        if 'wlan_config' in net_properties:
+            wl.ifconfig(config=net_properties['wlan_config'])
+        wl.connect(net_to_use, (sec, pwd), timeout=10000)
+        while not wl.isconnected():
+            machine.idle() # save power while waiting
+        print("Connected to "+net_to_use+" with IP address:" + wl.ifconfig()[0])
+
+    except Exception as e:
+        print("Failed to connect to any known network, going into AP mode")
+        wl.init(mode=WLAN.AP, ssid=original_ssid, auth=original_auth, channel=6, antenna=WLAN.INT_ANT)
+
+from network import LoRa
+import socket
+import machine
+import time
+
+# initialize LoRa in LORA mode
+# more params can also be given, like frequency, tx power and spreading factor
+lora = LoRa(mode=LoRa.LORA, frequency=868000000)
+
+# create a raw LoRa socket
+s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
+
+while True:
+    # send some data
+    s.setblocking(True)
+    s.send('Hello')
+
+    # get any data received...
+    s.setblocking(False)
+    data = s.recv(64)
+    print(data)
+
+    # wait a random amount of time
+    time.sleep(machine.rng() & 0x0F)

+ 40 - 0
main.py

@@ -0,0 +1,40 @@
+import os
+import machine
+import blueLE-test
+
+uart = machine.UART(0, 115200)
+os.dupterm(uart)
+
+known_nets = {
+    'UpUpUp': {'pwd': 't4k4tuk4l4nd2', 'wlan_config':  ('192.168.2.115', '255.255.255.0', '192.168.2.1', '192.168.2.1')},
+    'Vidit-Fabrik': {'pwd': '%m1n!5NK=$', 'wlan_config':  ('192.168.0.115', '255.255.255.0', '192.168.0.1', '192.168.0.1')}, # (ip, subnet_mask, gateway, DNS_server)
+}
+
+if machine.reset_cause() != machine.SOFT_RESET:
+    from network import WLAN
+    wl = WLAN()
+    wl.mode(WLAN.STA)
+    original_ssid = wl.ssid()
+    original_auth = wl.auth()
+
+    print("Scanning for known wifi nets")
+    available_nets = wl.scan()
+    nets = frozenset([e.ssid for e in available_nets])
+
+    known_nets_names = frozenset([key for key in known_nets])
+    net_to_use = list(nets & known_nets_names)
+    try:
+        net_to_use = net_to_use[0]
+        net_properties = known_nets[net_to_use]
+        pwd = net_properties['pwd']
+        sec = [e.sec for e in available_nets if e.ssid == net_to_use][0]
+        if 'wlan_config' in net_properties:
+            wl.ifconfig(config=net_properties['wlan_config'])
+        wl.connect(net_to_use, (sec, pwd), timeout=10000)
+        while not wl.isconnected():
+            machine.idle() # save power while waiting
+        print("Connected to "+net_to_use+" with IP address:" + wl.ifconfig()[0])
+
+    except Exception as e:
+        print("Failed to connect to any known network, going into AP mode")
+        wl.init(mode=WLAN.AP, ssid=original_ssid, auth=original_auth, channel=6, antenna=WLAN.INT_ANT)

+ 39 - 0
main.py333

@@ -0,0 +1,39 @@
+import os
+import machine
+
+uart = machine.UART(0, 115200)
+os.dupterm(uart)
+
+known_nets = {
+    'UpUpUp': {'pwd': 't4k4tuk4l4nd2', 'wlan_config':  ('192.168.2.115', '255.255.255.0', '192.168.2.1', '192.168.2.1')},
+    'Vidit-Fabrik': {'pwd': '%m1n!5NK=$', 'wlan_config':  ('192.168.0.115', '255.255.255.0', '192.168.0.1', '192.168.0.1')}, # (ip, subnet_mask, gateway, DNS_server)
+}
+
+if machine.reset_cause() != machine.SOFT_RESET:
+    from network import WLAN
+    wl = WLAN()
+    wl.mode(WLAN.STA)
+    original_ssid = wl.ssid()
+    original_auth = wl.auth()
+
+    print("Scanning for known wifi nets")
+    available_nets = wl.scan()
+    nets = frozenset([e.ssid for e in available_nets])
+
+    known_nets_names = frozenset([key for key in known_nets])
+    net_to_use = list(nets & known_nets_names)
+    try:
+        net_to_use = net_to_use[0]
+        net_properties = known_nets[net_to_use]
+        pwd = net_properties['pwd']
+        sec = [e.sec for e in available_nets if e.ssid == net_to_use][0]
+        if 'wlan_config' in net_properties:
+            wl.ifconfig(config=net_properties['wlan_config'])
+        wl.connect(net_to_use, (sec, pwd), timeout=10000)
+        while not wl.isconnected():
+            machine.idle() # save power while waiting
+        print("Connected to "+net_to_use+" with IP address:" + wl.ifconfig()[0])
+
+    except Exception as e:
+        print("Failed to connect to any known network, going into AP mode")
+        wl.init(mode=WLAN.AP, ssid=original_ssid, auth=original_auth, channel=6, antenna=WLAN.INT_ANT)

BIN
witty-pinout.jpg