示例#1
0
def pyboard_mqtt_test():
    led.on()
    ser = uart_open(4, 9600)
    #ser.init(9600, bits=8, parity=None, stop=1,timeout=10)
    m = pyboard_mqtt(ser)

    id = pyb.unique_id()
    id_s = binascii.hexlify(id)
    debug_print('id:' + id_s.decode())

    while True:
        m.pub(id_s, id_s + b'/C2D/', b'test mqtt pub string')
        time.sleep(5)
示例#2
0
    def __init__(self, config, display):

        self.__debug = config.get('debug')
        self.__display = display
        self.__server = config.get('mqtt_server')
        self.__topic = "emf_hub/ptt"
        self._id = str(ubinascii.hexlify(pyb.unique_id()), 'ascii')
        self.__next_ping = pyb.millis() + 60000

        self.__c = mqtt.MQTTClient(self._id, self.__server)

        # Connect to server
        self.__connect()
示例#3
0
    def start_wifi(self, skip_file=False):
        obj = None
        valid = False
        try:
            with open("wifi_settings.json", mode="rb") as f:
                obj = ujson.load(f)
                valid = True
        except KeyboardInterrupt:
            raise
        except OSError as exc:
            valid = False
            exclogger.log_exception(exc)
            exclogger.log_exception(
                "setting file probably not found or unusable")
        except Exception as exc:
            valid = False
            exclogger.log_exception(exc)
        if obj is not None:
            if "ssid" in obj:
                self.ssid = obj["ssid"]
                self.password = ""
                self.winc_security = network.WINC.OPEN
                self.winc_mode = network.WINC.MODE_STA
            else:
                valid = False
            if "password" in obj:
                self.password = obj["password"]
                if len(self.password) > 0:
                    self.winc_security = network.WINC.WPA_PSK
                else:
                    self.winc_security = network.WINC.OPEN
            if "security" in obj:
                secstr = obj["security"].lower()
                if "open" in secstr:
                    self.winc_security = network.WINC.OPEN
                elif "wpa" in secstr:
                    self.winc_security = network.WINC.WPA_PSK
                elif "psk" in secstr:
                    self.winc_security = network.WINC.WPA_PSK
                elif "wep" in secstr:
                    self.winc_security = network.WINC.WEP
            if "mode" in obj:
                modestr = obj["mode"].lower()
                if "soft" in modestr and "ap" in modestr:
                    self.winc_mode = network.WINC.MODE_AP
                elif "remote" in modestr:
                    self.winc_mode = network.WINC.MODE_AP
                elif "access" in modestr and "point" in modestr:
                    self.winc_mode = network.WINC.MODE_AP
        else:
            valid = False
            print("ERROR: could not load WiFi settings file")

        # if failed to connect to an expected router
        # start soft-AP
        if self.station_retries > 8:
            print(
                "ERROR: too many failed connection attempts, starting soft AP")
            valid = False

        if valid == False:
            self.ssid = "OpenMV-?"
            self.password = "******"
            self.winc_security = network.WINC.WEP
            self.winc_mode = network.WINC.MODE_AP

        if "?" in self.ssid:  # question mark is replaced with a unique identifier
            uidstr = ubinascii.hexlify(pyb.unique_id()).decode("ascii").upper()
            self.ssid = self.ssid.replace("?", uidstr)
        if self.winc_mode == network.WINC.MODE_AP:
            # limit SSID length
            if len(self.ssid) > 7 + 8:
                self.ssid = self.ssid[0:(7 + 8)]

        if valid == False:
            # write out a template for the JSON file
            obj = {}
            obj.update({"ssid": self.ssid})
            obj.update({"password": self.password})
            obj.update({"security": "wep"})
            obj.update({"mode": "soft ap"})
            try:
                with open("wifi_settings_template.json", mode="wb+") as f:
                    ujson.dump(obj, f)
                    print("wifi settings template file saved")
            except Exception as exc:
                exclogger.log_exception(exc)

        self.start_wifi_hw()
示例#4
0
print((pyb.millis() - start) // 5) # should print 3

# test udelay

pyb.udelay(-1)
pyb.udelay(0)
pyb.udelay(1)

start = pyb.millis()
pyb.udelay(17000)
print((pyb.millis() - start) // 5) # should print 3

# other

pyb.disable_irq()
pyb.enable_irq()

print(pyb.freq())

print(pyb.have_cdc())

pyb.hid((0, 0, 0, 0)) # won't do anything

pyb.rng()

pyb.sync()

print(len(pyb.unique_id()))

pyb.wfi()
示例#5
0
文件: main.py 项目: Kimbsy/EMF_20016
else:
	wifi.connect()

#Init GFX and Buttons
ugfx.init()
buttons.init()

#Setup Databases
db = database.Database()
inbox = database.Database(filename='inbox.json')

#Server Address
server = 'badge.emf.camp'

#Get CPU ID
id = str(ubinascii.hexlify(pyb.unique_id()), 'ascii')

#Get MSISDN
mynumber = None
myNumber()

# Setup Sequence ID
if db.get('msgseq') == None:
	db.set('msgseq', 0)
	db.flush()
else:
	pass


#Setup and Connect MQTT
c = mqtt.MQTTClient('badge'+id, server)