Ejemplo n.º 1
0
    def _init_mqtt(self):
        self.bs_config = bluestone_config.BluestoneConfig(
            'bluestone_config.json')
        self.bs_data_config = bluestone_config.BluestoneConfig(
            'bluestone_data.json')
        self.bs_gpio = bluestone_gpio.BluestoneGPIO()
        self.bs_pwm = bluestone_pwm.BluestonePWM()
        self.bs_fota = bluestone_fota.BluestoneFOTA()
        self.bs_uart = bluestone_uart.BlueStoneUart(None)

        # 创建一个MQTT实例
        self.client = MQTTClient(client_id=self.client_id,
                                 server=self.server,
                                 port=self.port,
                                 user=self.user,
                                 password=self.password,
                                 keepalive=30)
        _mqtt_log.info(
            "Start a new mqtt client, id:{}, server:{}, port:{}".format(
                self.client_id, self.server, self.port))

        self.client.set_callback(self._sub_callback)  # 设置消息回调
        self.client.connect()  # 建立连接

        #sub_topic = self.subscribe_topic.format(self.sn)
        _mqtt_log.info("Subscribe topic is {}".format(self.subscribe_topic))
        self.client.subscribe(self.subscribe_topic)  # 订阅主题
Ejemplo n.º 2
0
    def init(self):
        self.bs_config = bluestone_config.BluestoneConfig(
            'bluestone_config.json')
        self.bs_data_config = bluestone_config.BluestoneConfig(
            'bluestone_data.json')
        self.bs_gpio = bluestone_gpio.BluestoneGPIO()
        self.bs_pwm = bluestone_pwm.BluestonePWM()
        self.bs_fota = bluestone_fota.BluestoneFOTA()
        self.bs_uart = bluestone_uart.BlueStoneUart(None)

        # 创建一个MQTT实例
        self.client = TXyun(self.product_id, self.device_name, None,
                            self.product_secret)
        _mqtt_log.info("The mqtt client is started")

        self.client.setMqtt()  # 设置mqtt
        self.client.setCallback(self._sub_callback)  # 设置消息回调
        self.client.subscribe(self.subscribe_topic)  # 订阅主题
        self.client.start()
Ejemplo n.º 3
0
def system_init():
    global bs_config, bs_data_config, bs_mqtt
    '''
    如果程序包含网络相关代码,必须执行wait_network_connected() 等待网络就绪(拨号成功);
    '''
    #TODO: no need to check network connection each time
    system_log.info("Check network connection")
    checknet.wait_network_connected()

    if bs_config == None:
        system_log.info("Init system configuration file")
        bs_config = bluestone_config.BluestoneConfig('bluestone_config.json')
        config = bs_config.init_config()

    if bs_data_config == None:
        system_log.info("Init data configuration file")
        bs_data_config = bluestone_config.BluestoneConfig(
            'bluestone_data.json')
        data_config = bs_data_config.init_config()

    if bs_mqtt == None:
        system_log.info("Init tencent mqtt service")
        init_mqtt_tencent(config)
Ejemplo n.º 4
0
 def _init(self):
     self.bs_config = bluestone_config.BluestoneConfig(
         'bluestone_config.json')
     self.bs_data_config = bluestone_config.BluestoneConfig(
         'bluestone_data.json')
Ejemplo n.º 5
0
 def start(self):
     self.bs_config = bluestone_config.BluestoneConfig('config.json')
Ejemplo n.º 6
0
    global bs_aht10, bs_gpio

    bs_aht10 = bluestone_temperature.BluestoneTemperature()
    bs_aht10.aht10_init()

    bs_gpio = bluestone_gpio.BluestoneGPIO()


if __name__ == '__main__':
    utime.sleep(5)
    checknet.poweron_print_once()

    start_network()

    system_log.info("Init system configuration file")
    bs_config = bluestone_config.BluestoneConfig('bluestone_config.json')
    config = bs_config.init_config()

    system_log.info("Init data configuration file")
    bs_data_config = bluestone_config.BluestoneConfig('bluestone_data.json')
    data_config = bs_data_config.init_config()

    system_log.info("Init aht10 and gpio services")
    init_service()

    #system_log.info("Init mqtt service")
    #init_mqtt(config)

    system_log.info("Init tencent mqtt service")
    init_mqtt_tencent(config)