Ejemplo n.º 1
0
def send_SOS():
    """报警,红灯闪烁,发送位置信息"""
    led.on('RED')
    gps = up501.read()
    sx1278.send_str(gps)
    logger.debug('send_SOS ok!')
    led.off('RED')
Ejemplo n.º 2
0
    def show(self, now):
        """Display this page

        :param now: The current time

        :return: Finished showing for this schedule
        """
        led.on(led.RED)
        starwars.play()
        led.off()
        return False
Ejemplo n.º 3
0
    """ 创建日志文件 """
    fields = ['datetime', 'RSSI', 'SNR', 'msg']
    dir_path = os.path.join(root_path, 'lora_data')
    os.makedirs(dir_path, exist_ok=True)
    now = datetime.now()
    file_name = now.strftime('%Y%m%d') + '_rx.csv'
    file_path = os.path.join(dir_path, file_name)
    if not os.path.exists(file_path):
        with open(file_path, 'w') as fw:
            fw.write(','.join(fields) + '\n')
    return file_path


if __name__ == '__main__':
    # 创建日志文件
    log_file = csv_log_create()
    while True:
        PyLora.receive()  # put into receive mode
        while not PyLora.packet_available():
            # wait for a package
            led.off(u'GREEN')
        led.on(u'GREEN')
        now = datetime.now().strftime('%Y%m%d%H%M%S')
        rssi = str(PyLora.packet_rssi())
        snr = str(PyLora.packet_snr())
        msg = PyLora.receive_packet().decode()
        data = [now, rssi, snr, msg]
        logger.debug('datetime: {}, RSSI: {}, SNR: {}, msg: {}'.format(*data))
        with open(log_file, 'a') as fa:
            fa.write(','.join(data) + '\n')
Ejemplo n.º 4
0
    fields = ['datetime', 'temperatue', 'humidity', 'pressure']
    dir_path = os.path.join(root_path, 'lora_data')
    os.makedirs(dir_path, exist_ok=True)
    now = datetime.now()
    file_name = now.strftime('%Y%m%d') + '_tx.csv'
    file_path = os.path.join(dir_path, file_name)
    if not os.path.exists(file_path):
        with open(file_path, 'w') as fw:
            fw.write(','.join(fields) + '\n')
    return file_path


if __name__ == '__main__':
    # 创建日志文件
    log_file = csv_log_create()
    while True:
        led.on('RED')
        now = datetime.now().strftime('%Y%m%d%H%M%S')
        temperatue, pressure = ms8607.get_temperature_pressure()
        humidity = ms8607.get_humidity()
        data = [str(x) for x in [now, temperatue, humidity, pressure]]
        logger.debug(
            'datetime: {}, temperatue: {}, humidity: {}, pressure: {}'.format(
                *data))
        msg = ','.join(data) + '\n'
        with open(log_file, 'a') as fa:
            fa.write(msg)
        PyLora.send_packet(msg.encode())
        led.off('RED')
        # sleep(1)
Ejemplo n.º 5
0
 def onStrip(self, start, end):
     for led in self.leds[start:end]:
         led.on()
Ejemplo n.º 6
0
 def onAll(self):
     for led in self.leds:
         led.on()
Ejemplo n.º 7
0
def main():
    # 系统启动后黄灯亮
    led.on('YELLOW')

    # 导入预测模型
    clf = import_model()
    if clf is None:
        raise Exception('模型导入失败!')

    # 报警函数, 重复5次
    sos_cb = send_SOS_repeat_gen(5)

    # 日志配置
    env_path = os.path.join(root_path, 'env_data')
    env_fields = [
        'datetime', 'temperature(℃)', 'humidity(%)', 'pressure(mbar)',
        'hazardous'
    ]
    lightning_path = os.path.join(root_path, 'lightning_data')
    lightning_fields = ['datetime', 'events', 'distance(KM)', 'hazardous']
    os.makedirs(env_path, exist_ok=True)
    os.makedirs(lightning_path, exist_ok=True)

    def env_monitor():
        # 读取测量数据
        temperatue, pressure = ms8607.get_temperature_pressure()
        humidity = ms8607.get_humidity()
        # 预测是否下雨, 是则报警
        mx = np.array([temperatue, humidity, pressure]).reshape(1, -1)
        res = clf.predict(mx)[0]
        # 写入日志
        now = datetime.now()
        data = [
            now.strftime('%Y%m%d%H%M%S'), temperatue, humidity, pressure, res
        ]
        append_data_to_file(data, env_fields, env_path, now)
        logger.debug(data)
        # 报警
        if res:
            sos_cb()

    def lightning_monitor():
        # 读取数据
        distance = as3935.get_distance()
        events = as3935.get_INT_res()
        res = False
        # 闪电事件为8
        if events == 0x08:
            res = True
        # 写入日志
        now = datetime.now()
        data = [now.strftime('%Y%m%d%H%M%S'), events, distance, res]
        append_data_to_file(data, lightning_fields, lightning_path, now)
        logger.debug(data)

    # 绑定事件, 事件回调的实时性比定时监控更强
    # 如有闪电发生,则报警
    as3935.lightning_cbs.append(sos_cb)

    # 执行定时监控任务
    while True:
        env_monitor()
        lightning_monitor()
        sleep(60)
        pass