pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
200 stars 166 forks source link

Pygate lost connection to ttn #497

Closed maxklt closed 4 years ago

maxklt commented 4 years ago

Hello,

I have a Pygate with a Gpy attached, and connect the Pygate to TTN via LTE (1nce - LTE Cat-NB1).

There is a radio mast about 100m air-line distance at the same height as the Pygate, the Gpy has full network connection throughout and no breaks.

It works very well until after an undefined time (between 15min and 12 hours) the connection to the TTN network is lost and the gateway is offline in the TTN console (webapp and ttnctl), in the 1nce web interface the Gpy is listed as connected.

(Nodes can send or receive data to the TTN network during this time without any problems)

I would be very happy about help, it is unfortunately very frustrating, because I have been looking for a long time for the error but can't find it.

The code and the config are attached

Subquestion: Is it possible to test programmatically if the connection to ttn is active? (like e.g. lte.is_connected())

Used hardware: Pygate & Gpy

Firmware Version: Pycom MicroPython 1.20.2.rc11 [v1.11-d574024] on 2020-08-25; GPy with ESP32

from network import LTE
import time
import machine
from machine import RTC
import pycom

off = 0x000000
white = 0xffffff
red = 0x8a0000
green = 0x007f00
orange = 0xff7300
blue = 0x035afc
yellow = 0xffff00
purple = 0xf700ff

print('\nStarting LoRaWAN concentrator')

pycom.heartbeat(False)

def machine_cb(arg):
    evt = machine.events()
    print("-------------------------")
    print(evt)
    print("-------------------------")
    if (evt & machine.PYGATE_START_EVT):
        pycom.rgbled(green)
    elif (evt & machine.PYGATE_ERROR_EVT):
        pycom.rgbled(red)
    elif (evt & machine.PYGATE_STOP_EVT):
        pycom.rgbled(off)

# register callback function
machine.callback(trigger=(machine.PYGATE_START_EVT |
                          machine.PYGATE_STOP_EVT | machine.PYGATE_ERROR_EVT), handler=machine_cb)

# setup LTE
lte = LTE()

if not lte.isconnected():
    # Modem does not connect successfully without first being reset.
    print("Resetting LTE modem ... ", end='')
    lte.send_at_cmd('AT^RESET')
    print("OK")
    time.sleep(1)

    if not lte.isattached():
        print("Attaching to LTE network ", end='')
        lte.attach(band=8, apn="iot.1nce.net")
        arc = 0
        while(True):
            if arc >= 60:
                machine.reset()

            if lte.isattached():
                pycom.rgbled(purple)
                time.sleep(0.1)
                pycom.rgbled(off)
                print(" OK")
                lte.send_at_cmd("AT+CSQ")
                break

            print('.', end='')
            arc += 1
            time.sleep(1)

    if not lte.isconnected():
        print("Connecting on LTE network ", end='')
        lte.connect()
        crc = 0
        while(True):
            if crc >= 30:
                machine.reset()

            if lte.isconnected():
                pycom.rgbled(orange)
                time.sleep(0.1)
                pycom.rgbled(off)
                print(" OK")
                break

            print('.', end='')
            crc += 1
            time.sleep(1)

# Sync time via NTP server for GW timestamps on Events
print('Syncing RTC via ntp...', end='')
rtc = RTC()
rtc.ntp_sync(server="pool.ntp.org")

while not rtc.synced():
    print('.', end='')
    time.sleep(.5)
print(" OK\n")

# Read the GW config file from Filesystem
fp = open('/flash/config.json', 'r')
buf = fp.read()

# Start the Pygate
print("------ start paygate ------", end="\n\n")

machine.pygate_init(buf)

# disable degub messages
# machine.pygate_debug_level(1)

# while True:
#     time.sleep(1)
#     if not lte.isconnected():
#         pycom.rgbled(red)
#         time.sleep(5)
#         machine.pygate_deinit()
#         machine.pygate_reset()
{
    "SX1301_conf": {
        "lorawan_public": true,
        "clksrc": 1,
        "antenna_gain": 0,
        "radio_0": {
            "enable": true,
            "type": "SX1257",
            "freq": 867500000,
            "rssi_offset": -164.0,
            "tx_enable": true,
            "tx_freq_min": 863000000,
            "tx_freq_max": 870000000
        },
        "radio_1": {
            "enable": true,
            "type": "SX1257",
            "freq": 868500000,
            "rssi_offset": -164.0,
            "tx_enable": false
        },
        "chan_multiSF_0": {
            "enable": true,
            "radio": 1,
            "if": -400000
        },
        "chan_multiSF_1": {
            "enable": true,
            "radio": 1,
            "if": -200000
        },
        "chan_multiSF_2": {
            "enable": true,
            "radio": 1,
            "if": 0
        },
        "chan_multiSF_3": {
            "enable": true,
            "radio": 0,
            "if": -400000
        },
        "chan_multiSF_4": {
            "enable": true,
            "radio": 0,
            "if": -200000
        },
        "chan_multiSF_5": {
            "enable": true,
            "radio": 0,
            "if": 0
        },
        "chan_multiSF_6": {
            "enable": true,
            "radio": 0,
            "if": 200000
        },
        "chan_multiSF_7": {
            "enable": true,
            "radio": 0,
            "if": 400000
        },
        "chan_Lora_std": {
            "enable": true,
            "radio": 1,
            "if": -200000,
            "bandwidth": 250000,
            "spread_factor": 7
        },
        "chan_FSK": {
            "enable": true,
            "radio": 1,
            "if": 300000,
            "bandwidth": 125000,
            "datarate": 50000
        },
        "tx_lut_0": {
            "pa_gain": 0,
            "mix_gain": 5,
            "rf_power": 9,
            "dig_gain": 3
        },
        "tx_lut_1": {
            "pa_gain": 0,
            "mix_gain": 5,
            "rf_power": 9,
            "dig_gain": 3
        },
        "tx_lut_2": {
            "pa_gain": 0,
            "mix_gain": 5,
            "rf_power": 9,
            "dig_gain": 3
        },
        "tx_lut_3": {
            "pa_gain": 0,
            "mix_gain": 5,
            "rf_power": 9,
            "dig_gain": 3
        },
        "tx_lut_4": {
            "pa_gain": 0,
            "mix_gain": 5,
            "rf_power": 9,
            "dig_gain": 3
        },
        "tx_lut_5": {
            "pa_gain": 0,
            "mix_gain": 5,
            "rf_power": 9,
            "dig_gain": 3
        },
        "tx_lut_6": {
            "pa_gain": 0,
            "mix_gain": 5,
            "rf_power": 9,
            "dig_gain": 3
        },
        "tx_lut_7": {
            "pa_gain": 0,
            "mix_gain": 6,
            "rf_power": 11,
            "dig_gain": 3
        },
        "tx_lut_8": {
            "pa_gain": 0,
            "mix_gain": 5,
            "rf_power": 13,
            "dig_gain": 2
        },
        "tx_lut_9": {
            "pa_gain": 0,
            "mix_gain": 8,
            "rf_power": 14,
            "dig_gain": 3
        },
        "tx_lut_10": {
            "pa_gain": 0,
            "mix_gain": 6,
            "rf_power": 15,
            "dig_gain": 2
        },
        "tx_lut_11": {
            "pa_gain": 0,
            "mix_gain": 6,
            "rf_power": 16,
            "dig_gain": 1
        },
        "tx_lut_12": {
            "pa_gain": 0,
            "mix_gain": 9,
            "rf_power": 17,
            "dig_gain": 3
        },
        "tx_lut_13": {
            "pa_gain": 0,
            "mix_gain": 10,
            "rf_power": 18,
            "dig_gain": 3
        },
        "tx_lut_14": {
            "pa_gain": 0,
            "mix_gain": 11,
            "rf_power": 19,
            "dig_gain": 3
        },
        "tx_lut_15": {
            "pa_gain": 0,
            "mix_gain": 12,
            "rf_power": 20,
            "dig_gain": 3
        }
    },

    "gateway_conf": {
        "gateway_ID": "XXX",
        "server_address": "router.eu.thethings.network",
        "serv_port_up": 1700,
        "serv_port_down": 1700,
        "keepalive_interval": 10,
        "stat_interval": 30,
        "push_timeout_ms": 100,
        "forward_crc_valid": true,
        "forward_crc_error": false,
        "forward_crc_disabled": false
    }
}

First log of the Pymakr Console, after the TTN connection is lost

[3453045039] lorapf: INFO_ [main] report
2020-11-15 21:30:46 GMT #####
[UPSTREAM] ###
RF packets received by concentrator: 0
CRC_OK: 0.00%, CRC_FAIL: 0.00%, NO_CRC: 0.00%
RF packets forwarded: 0 (0 bytes)
PUSH_DATA datagrams sent: 1 (111 bytes)
PUSH_DATA acknowledged: 0.00%
[DOWNSTREAM] ###
PULL_DATA sent: 3 (100.00% acknowledged)
PULL_RESP(onse) datagrams received: 0 (0 bytes)
RF packets sent to concentrator: 0 (0 bytes)
TX errors: 0
TX rejected (collision packet): 0.00% (req:4, rej:0)
TX rejected (collision beacon): 0.00% (req:4, rej:0)
TX rejected (too late): 0.00% (req:4, rej:0)
TX rejected (too early): 0.00% (req:4, rej:0)
[JIT] ###
[jit] queue is empty
[GPS] ###
GPS sync is disabled
END #####
[3453045124] lorapf: WARN_ [up  ] ignored out-of sync PUSH_ACK packet buff_ack[0:109] != token[0:110]
[3453045175] lorapf: WARN_ [up  ] PUSH_ACK recieve timeout 1