class SigFoxSender: def __init__(self): # init Sigfox for RCZ1 (Europe) self.sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) # create a Sigfox socket self.socket = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) # make the socket blocking self.socket.setblocking(True) # configure it as uplink only self.socket.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) print('SigFox socket created') print('MAC: {} - ID: {} - RSSI: {} - PAC: {}'.format( hexlify(self.sigfox.mac()).decode(), hexlify(self.sigfox.id()).decode(), self.sigfox.rssi(), hexlify(self.sigfox.pac()).decode())) def getSignalStrength(self): return self.sigfox.rssi() def transformValue(self, value): # divide by 10 (convention as high values are expected at some point): transformed = value / 10 # cast value to int: transformed = int(transformed) # avoid negative values: transformed = 0 if (transformed < 0) else transformed # as we are packing the value in a single byte, make it 255 as max value: transformed = 255 if (transformed > 255) else transformed # return transformed value: return transformed def packMesageForSigFox(self, ozone, temperature, humidity): # casting floats to ints in values array (only ozone values): values = [self.transformValue(x) for x in ozone] # adding temperature and humidity to values array (casted to ints): values.append(int(temperature)) values.append(int(humidity)) # returning array packed for sigfox # sigfox custom grammar to use: ozone1::uint:8 ozone2::uint:8 ozone3::uint:8 ozone4::uint:8 ozone5::uint:8 ozone6::uint:8 ozone7::uint:8 ozone8::uint:8 ozone9::uint:8 ozone10::uint:8 temperature::uint:8 humidity::uint:8 return struct.pack('B' * len(values), *values) # return struct.pack('>BBBBBBBBBB', ozone..., int(temperature), int(humidity)) def sendMessage(self, message): return self.socket.send(message) def sendValues(self, ozone, temperature, humidity): res = self.sendMessage( self.packMesageForSigFox(ozone, temperature, humidity)) return res
class SigfoxNotifier(): def __init__(self): self._sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) self._socket = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) self._socket.setblocking(True) self._socket.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) self._temp = 0 self._last_use = 0 self._in_use = False print('sigfox mac: {}, pac: {}, id: {}'.format( binascii.hexlify(self._sigfox.mac()), binascii.hexlify(self._sigfox.pac()), binascii.hexlify(self._sigfox.id()))) def handle_notifications(self, notifications): for n in notifications: msg = bytearray() self._last_use = 0 if n.type == NotificationQueue.VIBRATION_STARTED: self._in_use = True elif n.type == NotificationQueue.VIBRATION_STOPPED: self._in_use = False self._last_use = n.data elif n.type == NotificationQueue.AMBIENT: self._temp = int(n.data[0]) else: print('unsupported event {}'.format(n.type)) continue msg.append(self._in_use) msg.extend(self._last_use.to_bytes(4, 'little')) msg.extend(self._temp.to_bytes(4, 'little')) print(list(msg)) self._socket.send(msg)
import time import pycom import binascii pycom.heartbeat(False) time.sleep(5) # init Sigfox for RCZ1 (Europe) sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ4) # create a Sigfox socket s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) # make the socket blocking s.setblocking(True) # configure it as uplink only s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) print('I am device ', binascii.hexlify(sigfox.mac()) ) msg_str = "0" sigfox.reset() s.send(msg_str) pycom.rgbled(0xFFFFFF) time.sleep(20) pycom.rgbled(0x0) # send some bytes
#l76 = L76GNSS(py, timeout=30) print('Boot at ', rtc.now()) RED = 0xff0000 GREEN = 0x00ff00 BLUE = 0x0000ff ORANGE = 0xffa500 CYAN = 0x00B7EB PINK = 0xFF69B4 OFF = 0x000000 # init Sigfox for RCZ1 (Europe) sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) print('Radio MAC=', binascii.hexlify(sigfox.mac())) print('Sigfox ID=', binascii.hexlify(sigfox.id())) # create a Sigfox socket s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) # make the socket blocking s.setblocking(True) # configure it as uplink only s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) cpt = 0 # TODO recv downlink for setting the RTC, ...
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868) print("mac", binascii.hexlify(lora.mac())) print(lora.frequency()) print(lora.has_joined()) print(lora.tx_power()) print(lora.power_mode()) #print(lora.stats()) except: pass try: print("===== sigfox =====================================") from network import Sigfox sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) print("id", binascii.hexlify(sigfox.id())) print("mac", binascii.hexlify(sigfox.mac())) print("pac", binascii.hexlify(sigfox.pac())) print("frequencies", sigfox.frequencies()) except: pass try: print("===== lte ========================================") from network import LTE lte = LTE() print("imei", lte.imei()) print("iccid", lte.iccid()) print("is_connected", lte.isconnected()) print("ue_coverage", lte.ue_coverage()) def send_at_cmd_pretty(cmd): return lte.send_at_cmd(cmd).replace('\r', '').strip().replace('\n\n','\n')
'air_sensor': SHT3x_single, 'node_version': NODE_VERSION, 'sync_counter': 0, 'sync_timestamp': 0, 'dev_eui': ubinascii.hexlify(lora.mac()).decode('ascii'), 'app_eui': config.APP_EUI, 'app_key': ubinascii.hexlify( ubinascii.unhexlify( (ubinascii.hexlify(sigfox.mac()) + "FFFE" + ubinascii.hexlify( machine.unique_id()).decode('ascii')))).decode('ascii'), 'wifi_ssid': config.WIFI_SSID, 'wifi_pw': config.WIFI_PW } # Data structure is: Ts, To, Tair, RH, Patm, Tsoil, Volt # For pyranometer board, in mV: channel_1, channel_2, channel_3, channel_4, channel_1*5.0, 0.0, Volt float_values = [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0] def save_config(my_config_dict): with open("/flash/my_config.json", 'w') as conf_file: