Exemplo n.º 1
0
def sync_time_from_GPS(verbose=False):
    #Start GPS
    py = Pytrack()
    l76 = L76GNSS(py, timeout=600)
    #start rtc
    rtc = machine.RTC()
    if verbose:
        print('Aquiring GPS signal....')
    set_LED_red()
    while (True):
       gps_datetime = l76.get_datetime()
       #case valid readings
       if gps_datetime[3]:
           day = int(gps_datetime[4][0] + gps_datetime[4][1] )
           month = int(gps_datetime[4][2] + gps_datetime[4][3] )
           year = int('20' + gps_datetime[4][4] + gps_datetime[4][5] )
           hour = int(gps_datetime[2][0] + gps_datetime[2][1] )
           minute = int(gps_datetime[2][2] + gps_datetime[2][3] )
           second = int(gps_datetime[2][4] + gps_datetime[2][5] )
           print("Current location: {}  {} ; Date: {}/{}/{} ; Time: {}:{}:{}".format(gps_datetime[0],gps_datetime[1], day, month, year, hour, minute, second))
           rtc.init( (year, month, day, hour, minute, second, 0, 0))
           break
    #Stop GPS
    set_LED_green()
    l76.stop(py)
    if verbose:
        print('RTC Set from GPS to UTC:', rtc.now())
    time.sleep(2)
    set_LED_off()
Exemplo n.º 2
0
def setup_gps():
    time.sleep(2)
    gc.enable()

    rtc = RTC()
    rtc.ntp_sync("pool.ntp.org")
    utime.sleep_ms(750)
    print('\nRTC Set from NTP to UTC:', rtc.now())
    utime.timezone(7200)
    print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')
    if rtc.now()[0] == 1970:
        print("Datetime could not be automatically set")
        date_str = (input(
            'Enter datetime as list separated by commas (y, m, d, h, min, s): '
        )).split(',')
        date_str = tuple([int(item) for item in date_str])
        try:
            rtc.init(date_str)
            print('Time successfully set to ', rtc.now(), '\n')
        except Exception:
            print("Failed to set time...")
    py = Pytrack()
    l76 = L76GNSS(py, timeout=30)
    print("GPS Timeout is {} seconds".format(30))
    chrono = Timer.Chrono()
    chrono.start()

    # while (True):
    #     coord = l76.coordinates(debug=True)
    #     print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free()))
    return l76
Exemplo n.º 3
0
def getGPS():
    py = Pytrack()
    l76 = L76GNSS(py, timeout=30)
    global coord
    coord = l76.coordinates()

    global latitude
    global longitude

    try:
        print(coord)

        if type(coord[1]) == "NoneType":
            pycom.rgbled(0xFF0000)
            latitude = round(0, 5)
        else:
            latitude = round(coord[1], 5)

        if type(coord[0]) == "NoneType":
            pycom.rgbled(0xFF0000)
            longitude = round(0, 5)
        else:
            longitude = round(coord[0], 5)
    except:
        pass
        print("can't get signal")
        longitude = 999
        latitude = 999

    global remote_address
    remote_address = remote_address_base
    remote_address += "?lat="
    remote_address += str(latitude)
    remote_address += "&lon="
    remote_address += str(longitude)
Exemplo n.º 4
0
def gnss_task():
    sd_mounted = False

    with thread_list_mutex:
        thread_list[_thread.get_ident()] = 'GNSS'

    # Mount SD if possible
    sd = SD()
    try:
        os.mount(sd, '/sd')
        os.listdir('/sd')
        sd_mounted = True
    except OSError:
        pass
    
    gnss = L76GNSS(py, timeout=5)

    while True:
        coord = gnss.rmc()
        printt(coord)

        # if sd_mounted:
        #     logfile = open('/sd/gnss.txt', 'a')
        #     logfile.write(logstring)
        #     logfile.close()

        time.sleep(2)
Exemplo n.º 5
0
def setup():
    global l76, lora
    if pycom.wifi_on_boot():  ## attempt to save battery
        pycom.wifi_on_boot(False)
    pycom.heartbeat(False)
    py = Pytrack()
    l76 = L76GNSS(py, timeout=30)
    lora = LoRa(mode=LoRa.LORAWAN)
Exemplo n.º 6
0
def getGPSCoord():
    py = Pytrack()
    l76 = L76GNSS(py, timeout=30)
    coord = l76.coordinates(debug=True)
    while coord == (None, None):
        coord = l76.coordinates(debug=True)
        print(coord)
    return coord
Exemplo n.º 7
0
 def __init__(self, logger):
     gc.enable()
     self.acc = LIS2HH12(pysense = None, sda = "P22", scl = "P21")
     py = Pytrack()
     self.gps = L76GNSS(py, timeout=30)
     self.py = Pycoproc()
     self.batteryTrack = 0
     self.Logger = logger
Exemplo n.º 8
0
def coordinates(l76=None):
    """Get latitude and longitude from GPS"""
    if l76 == None:
        l76 = L76GNSS(timeout=conf.GPS_TIMEOUT)
    try:
        latlng = l76.coordinates()
        time = int(latlng[2][6:])
        date = int("20" + latlng[2][4:6] + latlng[2][2:4] + latlng[2][:2])
        return (latlng[0], latlng[1], date, time)
    except:
        return (None, None, None, None)
Exemplo n.º 9
0
 def init_static():
     is_pytrack = True
     try:
         py = Pytrack()
         Gps.l76 = L76GNSS(py, timeout=30)
         #l76.coordinates()
         Gps._timer = Timer.Alarm(Gps.gps_periodic, 30, periodic=True)
         print("Pytrack detected")
     except:
         is_pytrack = False
         print("Pytrack NOT detected")
     #TODO: how to check if GPS is conencted
     return is_pytrack
Exemplo n.º 10
0
def location():
    from L76GNSS import L76GNSS
    l76 = L76GNSS(py, timeout=30)
    for attempt in range(10):
        coord = l76.coordinates()
        if coord[0]:
            break
        print(attempt, coord)
    log('location', coord)
    pybytes.send_signal(14, coord)
    # pybytes.send_signal(15, 'https://www.openstreetmap.org/#map=9/' + str(coord[0]) + '/' + str(coord[1]))
    pybytes.send_signal(
        15, 'https://www.openstreetmap.org/?mlat=' + str(coord[0]) + '&mlon=' +
        str(coord[1]))
Exemplo n.º 11
0
def getGPS(py, max_samples):
    """ Get GPS lng/lat by performing multiple GPS collections and then
    returning the most often seen results , after power on this can take a while
    but once coordinates stabilize the results will be returned """
    early_end_count = 10

    # Create a dictionary of coords and count
    coord_dict = {}
    gc.enable()

    # setup rtc
    rtc = machine.RTC()
    rtc.ntp_sync("pool.ntp.org")
    utime.sleep_ms(750)
    # print('\nRTC Set from NTP to UTC:', rtc.now())
    utime.timezone(7200)
    # print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')

    l76 = L76GNSS(py, timeout=30)
    valid_coord_count = 0

    print("getGPS: ", end="")

    for sample_number in range(max_samples):
        # time.sleep(1)

        coord = l76.coordinates()
        if coord[0] is None or coord[1] is None:
            blink(1, 0xff0000)  # red
            print(".", end='')
        else:
            blink(1, 0x00ff00)  # green
            print("^", end='')
            valid_coord_count += 1
            if coord in coord_dict:
                coord_dict[coord] += 1
            else:
                coord_dict[coord] = 1
        # print("coord_dict", coord_dict)
        # print("{} - {}".format(coord, sample_number))
        # End early if we have enough coord samples
        if valid_coord_count > early_end_count:
            print(" ")
            return most_common_coord(coord_dict)
    print(" ")
    return most_common_coord(coord_dict)
Exemplo n.º 12
0
def getGPS():
    global py
    try:
        l76 = L76GNSS(py)
        coord = dict(latitude='', longitude='', HDOP=0.0)
        loop_counter = 5
        if globalVars.gps_enabled == True:
            while coord['latitude'] == '' and coord[
                    'longitude'] == '' and loop_counter > 0:
                debug("GPS Acquisition, loop: " + str(loop_counter), "v")
                loop_counter = loop_counter - 1
                coord = l76.get_location(debug=False,
                                         tout=globalVars.gps_timeout)
                debug(
                    "HDOP: " + str(coord['HDOP']) + "Latitude: " +
                    str(coord['latitude']) + " - Longitude: " +
                    str(coord['longitude']), 'v')

            if coord['latitude'] != '' and coord['longitude'] != '':
                haversine(coord['latitude'], coord['longitude'],
                          globalVars.last_lat_tmp, globalVars.last_lon_tmp)
                big_endian_latitude = bytearray(
                    struct.pack(">I", int(coord['latitude'] * 1000000)))
                big_endian_longitude = bytearray(
                    struct.pack(">I", int(coord['longitude'] * 1000000)))

            dt = l76.getUTCDateTimeTuple(debug=False)
            if dt is not None:
                forceRTC(dt, "tuple")
                debug(
                    "Updating timestamp from GPS - " + str(utime.time()) +
                    " - GMT: " + str(utime.gmtime()), "v")
                globalVars.flag_rtc_syncro = True

        if (coord['latitude'] == '') or (coord['longitude'] == '') or (float(
                str(coord['HDOP'])) > float(globalVars.min_hdop)):
            return None, None
        else:
            globalVars.last_lat_tmp = coord['latitude']
            globalVars.last_lon_tmp = coord['longitude']
            return big_endian_latitude, big_endian_longitude

    except BaseException as e:
        checkError("Error getting GPS", e)
        return None, None
    def __init__(self, pymesh):
        self.pymesh = pymesh
        # read config file, or set default values
        node_dict = self.create_node_config_dict()
        self.node_ssid = node_dict['WIFI_SSID']
        self.node_pass = node_dict['WIFI_PASS']
        self.node_name = node_dict['NODE_NAME']
        self.mesh_freq = node_dict['MESH_FREQ']
        self.mesh_band = node_dict['MESH_BAND']
        self.mesh_spred = node_dict['SPREAD_FACT']
        self.mesh_key = node_dict['MESH_KEY']

        if uos.uname().sysname == 'FiPy':
            self.has_lte = True
        else:
            self.has_lte = False
        self.mac = str(pymesh.mesh.mesh.MAC)
        try:
            self.py = Pycoproc()
        except:
            self.exp31 = True
        self.rtc = RTC()
        try:
            self.l76 = L76GNSS(py, timeout=30)
            self.pytrack_s = True
            print("Pytrack")
        except:
            self.pytrack_s = False

        try:
            self.si = SI7006A20(py)
            self.mp = MPL3115A2(
                py, mode=ALTITUDE
            )  # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
            self.mpp = MPL3115A2(
                py, mode=PRESSURE
            )  # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters
            self.pysense_s = True
            print("Pysense")
        except:
            self.pysense_s = False

        if self.pysense_s == False and self.pytrack_s == False:
            print("EXP 3.1")
Exemplo n.º 14
0
    def setup(self):
        time.sleep(2)
        gc.enable()

        # setup rtc
        rtc = machine.RTC()
        rtc.ntp_sync("pool.ntp.org")
        utime.sleep_ms(750)
        utime.timezone(7200)

        py = Pytrack()
        self.gnss = L76GNSS(py, timeout=30)

        print("Waiting for GNSS connection...")
        # Unfortunately, the tuple comparison method - cmp() - is not available in MicroPython
        while(self.gnss.coordinates()[0] == None and self.gnss.coordinates()[1] == None):
            pass

        print("GNSS connection acquired")
Exemplo n.º 15
0
def set_GPS_timeout(l76=None):
    """Set the GPS timeout according to the number of satellites in view"""
    if l76 == None:
        l76 = L76GNSS(timeout=conf.GPS_TIMEOUT)
    if l76.check_satellites() < '04' and pycom.nvs_get('gpscount') < 2:
        pycom.nvs_set('gpscount', pycom.nvs_get('gpscount') + 1)
        conf.DEEP_SLEEP_PERIOD = 150  # 2 minutes 30s
    elif l76.check_satellites() < '04':
        pycom.nvs_set('gpscount', 0)
        conf.DEEP_SLEEP_PERIOD = 900  # 15 minutes
    else:
        #latlng  = l76.coordinates(1)
        """
        if latlng[0] == None or latlng[1] == None:
            conf.GPS_TIMEOUT = 300
            conf.DEEP_SLEEP_PERIOD = 60 # 1 minute
            return True
        else:
            conf.DEEP_SLEEP_PERIOD = 300 # 15 minutes
            return True
        """
        return True
    return False
Exemplo n.º 16
0
from L76GNSS import L76GNSS
from pytrack import Pytrack

time.sleep(2)
gc.enable()

# setup rtc
rtc = machine.RTC()
rtc.ntp_sync("pool.ntp.org")
utime.sleep_ms(750)
print('\nRTC Set from NTP to UTC:', rtc.now())
utime.timezone(7200)
print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')

py = Pytrack()
l76 = L76GNSS(py, timeout=30)

# sd = SD()
# os.mount(sd, '/sd')
# f = open('/sd/gps-record.txt', 'w')


# 2019-0715 Peter added to re-run test
def run():
    while (True):
        coord = l76.coordinates()
        # f.write("{} - {}\n".format(coord, rtc.now()))
        print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free()))


# 2019-0715 added
Exemplo n.º 17
0
# Set up the LoRa in longer range mode

lora = LoRa(mode=LoRa.LORA, region=LoRa.AS923)
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setblocking(False)
DevEUI = ubinascii.hexlify(lora.mac()).decode('ascii')

# Enable garbage collection

time.sleep(2)
gc.enable()

# Set up GPS with modest timeout

py = Pytrack()
l76 = L76GNSS(py)

last_lat = 13.736717
last_lon = 100.523186
last_alt = 0

while True:
    try:  
        battery = py.read_battery_voltage()  # Get battery
        gps = l76.gps_message('GGA')  # Gets coordinates


        lat = gps["Latitude"]
        lon = gps["Longitude"]
        alt = gps["Altitude"]
        timestamp = gps["UTCTime"]
Exemplo n.º 18
0
            frequency=868000000,
            tx_power=14,
            bandwidth=LoRa.BW_125KHZ,
            sf=7)
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setblocking(False)

## Enable garbage collection

time.sleep(2)
gc.enable()

## Set up GPS with modest timeout

py = Pytrack()
l76 = L76GNSS(py, timeout=10)

## Defaults for last known latitude, longitude

last_lon = 0
last_lat = 0

min_twitch = 0.000010  ## Attempts to reduce local twitchiness

while True:
    coord = l76.coordinates()  ## Gets coordinates
    if not coord == (None, None):
        lat, lon = coord
        if abs(lat - last_lat) > min_twitch or abs(lon -
                                                   last_lon) > min_twitch:
            s.send("%f,%f" % (lat, lon))  ## Send the coordinates over LoRa
Exemplo n.º 19
0
from network import Sigfox
from pytrack import Pytrack
#import urequests as requests
from L76GNSS import L76GNSS
import socket
import time
import pycom
import struct

py = Pytrack()
gps = L76GNSS(py, timeout=60)
print("connecting to Sigfox")
# init Sigfox for RCZ1 (Europe)
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)
# create a Sigfox socket
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
# make the socket blocking
s.setblocking(True)
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)

# Get coordinates from pytrack
coord = gps.coordinates()
lat, lng = coord

print(str(lat), ":", str(lng))
s.send(struct.pack('f', float(lat)) + struct.pack('f', float(lng)))
Exemplo n.º 20
0
import utime
from machine import RTC
from machine import SD
from machine import Timer
from L76GNSS import L76GNSS
from pytrack import Pytrack
import struct
# setup as a station

import gc
time.sleep(2)
gc.enable()

#Start GPS
py = Pytrack()
l76 = L76GNSS(py, timeout=600)
#start rtc
rtc = machine.RTC()
print('Aquiring GPS signal....')
#try to get gps date to config rtc
while (True):
    gps_datetime = l76.get_datetime()
    #case valid readings
    if gps_datetime[3]:
        day = int(gps_datetime[4][0] + gps_datetime[4][1] )
        month = int(gps_datetime[4][2] + gps_datetime[4][3] )
        year = int('20' + gps_datetime[4][4] + gps_datetime[4][5] )
        hour = int(gps_datetime[2][0] + gps_datetime[2][1] )
        minute = int(gps_datetime[2][2] + gps_datetime[2][3] )
        second = int(gps_datetime[2][4] + gps_datetime[2][5] )
        print("Current location: {}  {} ; Date: {}/{}/{} ; Time: {}:{}:{}".format(gps_datetime[0],gps_datetime[1], day, month, year, hour, minute, second))
Exemplo n.º 21
0
s.setblocking(True)

#### Pytrack

gc.enable()

# setup rtc
# rtc = machine.RTC()
# rtc.ntp_sync("pool.ntp.org")
# utime.sleep_ms(750)
# print('\nRTC Set from NTP to UTC:', rtc.now())
# utime.timezone(7200)
# print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')

py = Pytrack()
l76 = L76GNSS(py, timeout=5000)

# sd = SD()
# os.mount(sd, '/sd')
# f = open('/sd/gps-record.txt', 'w')

lpp = cayenneLPP.CayenneLPP(size=100, sock=s)

while (True):
    coord = l76.coordinates()
    if isinstance(coord, int):
        lpp.add_gps(3, coord, 2)
    #f.write("{} - {}\n".format(coord, rtc.now()))
    print(coord)
    lpp.send(reset_payload=True)
    time.sleep(60)
Exemplo n.º 22
0
gc.enable()

# setup rtc
rtc = machine.RTC()
rtc.ntp_sync("pool.ntp.org")
utime.sleep_ms(750)
print('\nRTC Set from NTP to UTC:', rtc.now())
utime.timezone(7200)
print('Adjusted from UTC to EST timezone', utime.localtime(), '\n')

py = Pycoproc()
if py.read_product_id() != Pycoproc.USB_PID_PYTRACK:
    raise Exception('Not a Pytrack')

time.sleep(1)
l76 = L76GNSS(py, timeout=30, buffer=512)

pybytes_enabled = False
if 'pybytes' in globals():
    if(pybytes.isconnected()):
        print('Pybytes is connected, sending signals to Pybytes')
        pybytes_enabled = True

# sd = SD()
# os.mount(sd, '/sd')
# f = open('/sd/gps-record.txt', 'w')

while (True):
    coord = l76.coordinates()
    #f.write("{} - {}\n".format(coord, rtc.now()))
    print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free()))
Exemplo n.º 23
0
import time
import binascii
import pycom
from network import LoRa

from CayenneLPP import CayenneLPP
from pytrack import Pytrack
from LIS2HH12 import LIS2HH12
from L76GNSS import L76GNSS

py = Pytrack()
li = LIS2HH12(py)

# after 60 seconds of waiting without a GPS fix it will
# return None, None
gnss = L76GNSS(py, timeout=120)

# Disable heartbeat LED
pycom.heartbeat(False)

# Initialize LoRa in LORAWAN mode.
lora = LoRa(mode=LoRa.LORAWAN)

# create an OTAA authentication parameters
app_eui = binascii.unhexlify('0101010101010101')
app_key = binascii.unhexlify('11B0282A189B75B0B4D2D8C7FA38548B')

print("DevEUI: %s" % (binascii.hexlify(lora.mac())))
print("AppEUI: %s" % (binascii.hexlify(app_eui)))
print("AppKey: %s" % (binascii.hexlify(app_key)))
Exemplo n.º 24
0
pycom.rgbled(0xFF00FF)
print('Connecting to MQTT...\n')
client_id = 'pytrack_{}'.format(hexlify(wlan.mac()).decode('utf-8'))
mqtt_client = MQTTClient(client_id, MQTT_SERVER, port=MQTT_PORT)
mqtt_client.connect()
print('Connected to MQTT as {}'.format(client_id))

pycom.rgbled(0x001400)

py = Pytrack()
li = LIS2HH12(py)

# after 240 seconds of waiting without a GPS fix it will
# return None, None
gnss = L76GNSS(py, timeout=240)

while True:
    pycom.rgbled(0x000014)

    print('\n\n** 3-Axis Accelerometer (LIS2HH12)')
    acceleration = li.acceleration()
    print('Acceleration', acceleration)
    roll = li.roll()
    print('Roll', roll)
    pitch = li.pitch()
    print('Pitch', pitch)

    payload = {
        'accelerometer_x': acceleration[0],
        'accelerometer_y': acceleration[1],
Exemplo n.º 25
0
py.setup_int_pin_wake_up(False)
py.setup_int_wake_up(True, True)
acc = LIS2HH12()
acc.enable_activity_interrupt(100, 200)  # Very sensitive
maxSleep = 86400  # Max time the device is allowed to sleep for (seconds). 24 hours

sigfox = Sigfox(mode=Sigfox.SIGFOX,
                rcz=Sigfox.RCZ1)  # init Sigfox for RCZ1 (Europe)
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)  # create a Sigfox socket
s.setblocking(True)  # make the socket blocking
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX,
             False)  # configure it as uplink only
sigfoxCounter = 0  # count numbre of sigfox trnasmissions (max 140 a day)

gc.enable()
l76 = L76GNSS(py, timeout=60)  # setup GPS

gc.collect()
noLock = 0
lock = False
pycom.rgbled(0xFF0000)  # red
print("Activity")
asleepTime = maxSleep - py.get_sleep_remaining()  # seconds, not accurate

print("We were asleep for ", asleepTime, " Seconds.")

while (lock == False) and (
        noLock < 6):  # Try get GPS 6 Times before giving up and going to Sleep
    coord = l76.coordinates(debug=False)
    print("{} - {} KB".format(coord, gc.mem_free() / 1000))
    if not all(coord):  # returns false if none is in the truple
Exemplo n.º 26
0
# Possible values of wakeup reason are:
WAKE_REASON_ACCELEROMETER = 1
WAKE_REASON_PUSH_BUTTON = 2
WAKE_REASON_TIMER = 4
WAKE_REASON_INT_PIN = 8

# Init Pytrack
py = Pytrack()
fw_version = py.read_fw_version()
print("Pytrack firmware version: " + str(fw_version))
# Get wakeup reason
wakeup = py.get_wake_reason()
print("Wakeup reason: " + str(wakeup) + "; Aproximate sleep remaining: " +
      str(py.get_sleep_remaining()) + " sec")
# Init GPS
gps = L76GNSS(py, timeout=10)
# Init accelerometer
acc = LIS2HH12()
# Init CayenneLPP buffer
lpp = CayenneLPP()
# Init LoRaWAN
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868, adr=config.ADR)
# Restore LoRaWAN states after deepsleep
lora.nvram_restore()


def blink_led(color, delay=0.2):
    """ blink led for a short time """
    pycom.rgbled(color)
    time.sleep(delay)
    pycom.rgbled(config.COLOR_BLACK)
Exemplo n.º 27
0
        pybytes.connect()
        '''

        # Please put your USER code below this line

        # SEND SIGNAL
        # You can currently send Strings, Int32, Float32 and Tuples to pybytes using this method.
        # pybytes.send_signal(signalNumber, value)

        # SEND SENSOR DATA THROUGH SIGNALS
        # # If you use a Pysense, some libraries are necessary to access its sensors
        # # you can find them here: https://github.com/pycom/pycom-libraries
        #
        # # Include the libraries in the lib folder then import the ones you want to use here:
        from L76GNSS import L76GNSS
        gnss = L76GNSS()

        from LIS2HH12 import LIS2HH12
        accel = LIS2HH12()

        # Import what is necessary to create a thread
        import _thread
        import time
        from machine import Pin

        last_alert_time = time.time()

        def crash_detected(arg):
            global last_alert_time
            if (time.time() - last_alert_time) > 60:  # 60 seconds since last alert
                x, y, z = accel.acceleration()
Exemplo n.º 28
0
vBatt = 0
current_rate = norm_rate
last_batt_check = 0
last_send_time = 0
last_LED_check = 0
LED_count = 0

# instantiate libraries
try:
    # Initialize PyTrack
    pytrack = Pytrack()
except Exception as e:
    print("Pytrack initialisation: ERROR")
    time.sleep(0.5)
    machine.reset()
l76 = L76GNSS(pytrack)
acc = LIS2HH12()
gps = MicropyGPS(location_formatting='dd')  # return decimal degrees from GPS
wdt = WDT(timeout=WDtimeout)  # enable a Watchdog timer with a specified timeou
rtc = machine.RTC()
led = RGBLED(10)


def update_LED():
    # continuously update the status of the unit via the onboard LED
    global gps
    global msgSent
    global ledInterval
    global last_LED_check
    global LED_count
    ledColour = 0x000000
Exemplo n.º 29
0
import machine  # pour pouvoir géré des fichier
import pycom  # pour le gestion du module pycom (dans notre cas la led)
import socket  # pour lire les message recus
import time  # pour la gestion des temps d'attente
from network import LoRa  #pour etre en mode LoRa
from L76GNSS import L76GNSS  # pour le module gps
from pytrack import Pytrack  # shield du modul gps

lora = LoRa(mode=LoRa.LORA,
            region=LoRa.EU868,
            bandwidth=LoRa.BW_250KHZ,
            preamble=20,
            sf=12)  #configuration initiale
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
py = Pytrack()  # initialisation du shield
l76 = L76GNSS(py, timeout=10)  # initialisation GPS

pycom.heartbeat(
    False)  # on stop les pulsations indiquant que le module est allumé
pycom.rgbled(0x7f0000)  # on initialise la led en rouge

with open(
        'data.txt', 'a'
) as datafile:  #création de du fichier data.txt sur le module si il n'est pas present, ou sinon on l'ouvre en mode ajout de data.
    datafile.write(
        "\n\n\n")  # 3 saut à la ligne pour diferentier les data precedentes
datafile.close()  # on referme le fichier

while (True):
    s.setblocking(False)  # module en position d'écoute
    data = s.recv(64)  # data avec un buffer de 64
Exemplo n.º 30
0
 def __init__(self, py, to):
     # setup GPS
     self.L76 = L76GNSS(py, timeout=to)