diff --git a/pymesh/pymesh_frozen/lib/pymesh_config.py b/pymesh/pymesh_frozen/lib/pymesh_config.py index 798f8f8..74a0292 100644 --- a/pymesh/pymesh_frozen/lib/pymesh_config.py +++ b/pymesh/pymesh_frozen/lib/pymesh_config.py @@ -5,7 +5,6 @@ see the Pycom Licence v1.0 document supplied with this file, or available at https://www.pycom.io/opensource/licensing ''' -import ubinascii import json from network import LoRa @@ -78,10 +77,7 @@ def write_config(pymesh_config, force_restart = False): time.sleep(1) machine.deepsleep(1000) - def check_mac(pymesh_config): - lora = LoRa(mode=LoRa.LORA, region= LoRa.EU868) - MAC = int(str(ubinascii.hexlify(lora.mac()))[2:-1], 16) - + def check_mac(pymesh_config, MAC): if pymesh_config.get('MAC') is None: # if MAC config unspecified, set it to LoRa MAC print_debug(3, "Set MAC in config file as " + str(MAC)) @@ -102,7 +98,7 @@ def check_mac(pymesh_config): print_debug(3, "MAC ok" + str(MAC)) - def read_config(): + def read_config(MAC): file = PymeshConfig.CONFIG_FILENAME pymesh_config = {} error_file = True @@ -138,10 +134,10 @@ def read_config(): pymesh_config['br_ena'] = PymeshConfig.BR_ENABLE pymesh_config['br_prio'] = PymeshConfig.BR_PRIORITY - PymeshConfig.check_mac(pymesh_config) + PymeshConfig.check_mac(pymesh_config, MAC) print_debug(3, "Default settings:" + str(pymesh_config)) PymeshConfig.write_config(pymesh_config, True) - PymeshConfig.check_mac(pymesh_config) + PymeshConfig.check_mac(pymesh_config, MAC) print_debug(3, "Settings:" + str(pymesh_config)) return pymesh_config diff --git a/pymesh/pymesh_frozen/lorawan/main.py b/pymesh/pymesh_frozen/lorawan/main.py index 223cee6..33f33da 100644 --- a/pymesh/pymesh_frozen/lorawan/main.py +++ b/pymesh/pymesh_frozen/lorawan/main.py @@ -1,5 +1,7 @@ -import pycom import time +import ubinascii +import pycom +from network import LoRa try: from pymesh_config import PymeshConfig @@ -28,8 +30,11 @@ def new_message_cb(rcv_ip, rcv_port, rcv_data): pycom.heartbeat(False) +lora = LoRa(mode=LoRa.LORA, region= LoRa.EU868) +lora_mac = int(str(ubinascii.hexlify(lora.mac()))[2:-1], 16) + # read config file, or set default values -pymesh_config = PymeshConfig.read_config() +pymesh_config = PymeshConfig.read_config(lora_mac) #initialize Pymesh pymesh = Pymesh(pymesh_config, new_message_cb) diff --git a/pymesh/pymesh_frozen/main.py b/pymesh/pymesh_frozen/main.py index 4cf6fbd..5d7c17a 100644 --- a/pymesh/pymesh_frozen/main.py +++ b/pymesh/pymesh_frozen/main.py @@ -1,5 +1,7 @@ -import pycom import time +import ubinascii +import pycom +from network import LoRa try: from pymesh_config import PymeshConfig @@ -28,8 +30,11 @@ def new_message_cb(rcv_ip, rcv_port, rcv_data): pycom.heartbeat(False) +lora = LoRa(mode=LoRa.LORA, region= LoRa.EU868) +lora_mac = int(str(ubinascii.hexlify(lora.mac()))[2:-1], 16) + # read config file, or set default values -pymesh_config = PymeshConfig.read_config() +pymesh_config = PymeshConfig.read_config(lora_mac) #initialize Pymesh pymesh = Pymesh(pymesh_config, new_message_cb) diff --git a/pymesh/pymesh_frozen/main_BR.py b/pymesh/pymesh_frozen/main_BR.py index 3c53257..fdb9780 100644 --- a/pymesh/pymesh_frozen/main_BR.py +++ b/pymesh/pymesh_frozen/main_BR.py @@ -1,5 +1,7 @@ import time +import ubinascii import pycom +from network import LoRa # 2 = test pybytes OTA feature # 4 = added device_id (pybytes token) in the packets to BR @@ -66,8 +68,11 @@ def new_br_message_cb(rcv_ip, rcv_port, rcv_data, dest_ip, dest_port): pycom.heartbeat(False) +lora = LoRa(mode=LoRa.LORA, region= LoRa.EU868) +lora_mac = int(str(ubinascii.hexlify(lora.mac()))[2:-1], 16) + # read config file, or set default values -pymesh_config = PymeshConfig.read_config() +pymesh_config = PymeshConfig.read_config(lora_mac) #initialize Pymesh pymesh = Pymesh(pymesh_config, new_message_cb) diff --git a/pymesh/readme.md b/pymesh/readme.md new file mode 100644 index 0000000..0be1a7a --- /dev/null +++ b/pymesh/readme.md @@ -0,0 +1,3 @@ +# For reference only + +This library is the open-source part of the Pymesh LoRa Firmware which can be provisioned through Pybytes and cannot be used as stand-alone on a Pybytes or Pygate type firmware. Please check the [Pycom Documentation](https://docs.pycom.io/pybytes/pymeshintegration/provisioning/) on how to get Pymesh type firmware provisioned to your device. You will not have to use this library in your project or flash it to your device separately, as it is already included in the firmware. diff --git a/shields/pysense_2.py b/shields/pysense_2.py index 4edcd95..ff793e7 100644 --- a/shields/pysense_2.py +++ b/shields/pysense_2.py @@ -48,7 +48,7 @@ lt = LTR329ALS01(py) -print("Light (channel Blue, channel Red): " + str(lt.light()," Lux: ", str(lt.lux()), "lx")) +print("Light (channel Blue, channel Red): " + str(lt.light())," Lux: ", str(lt.lux()), "lx") li = LIS2HH12(py) print("Acceleration: " + str(li.acceleration())) @@ -69,4 +69,4 @@ pybytes.send_signal(3, lt.light()) pybytes.send_signal(4, li.acceleration()) pybytes.send_battery_level(int(battery_percentage)) - print("Sent data to pybytes") \ No newline at end of file + print("Sent data to pybytes")