From f24b3fbbbfeb3a681cb92e049db9e25db2a6e7c6 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Mon, 12 Apr 2021 15:37:56 +0200 Subject: [PATCH] makefile release (#141) --- .gitignore | 12 ++++ Makefile | 102 ++++++++++++++++++++++++++++ shields/pyscan_1.py | 126 +++++++++++++++++++++-------------- shields/pyscan_1_nfc.py | 75 --------------------- shields/pyscan_1_pybytes.py | 98 --------------------------- shields/pysense_1.py | 23 ++++++- shields/pysense_1_pybytes.py | 52 --------------- shields/pysense_2.py | 20 ++++++ shields/pytrack_1.py | 16 +++++ shields/pytrack_1_pybytes.py | 51 -------------- shields/pytrack_2.py | 12 +++- 11 files changed, 257 insertions(+), 330 deletions(-) create mode 100644 Makefile delete mode 100644 shields/pyscan_1_nfc.py delete mode 100644 shields/pyscan_1_pybytes.py delete mode 100644 shields/pysense_1_pybytes.py delete mode 100644 shields/pytrack_1_pybytes.py diff --git a/.gitignore b/.gitignore index beced4e..e943765 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,15 @@ *.conf .DS_Store +pyscan/* +pysense/* +pysense2/* +pytrack/* +pytrack2/* + +pyscan.zip +pysense.zip +pysense2.zip +pytrack.zip +pytrack2.zip + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..17034ef --- /dev/null +++ b/Makefile @@ -0,0 +1,102 @@ +release: pyscan pysense pysense2 pytrack pytrack2 + + +pyscan: + rm -rf pyscan + rm -f pyscan.zip + @echo "Making Pyscan" + mkdir pyscan + mkdir pyscan/lib + #sensors + cp shields/lib/LIS2HH12.py pyscan/lib/ + cp shields/lib/MFRC630.py pyscan/lib/ + cp shields/lib/SI7006A20.py pyscan/lib/ + cp shields/lib/LTR329ALS01.py pyscan/lib/ + #pycoproc + cp shields/lib/pycoproc_1.py pyscan/lib/ + #example + cp shields/pyscan_1.py pyscan/main.py + + zip -r pyscan.zip pyscan + +pysense: + rm -rf pysense + rm -f pysense.zip + @echo "Making Pysense" + mkdir pysense + mkdir pysense/lib + # sensors + cp shields/lib/LIS2HH12.py pysense/lib/ + cp shields/lib/LTR329ALS01.py pysense/lib/ + cp shields/lib/MPL3115A2.py pysense/lib/ + cp shields/lib/SI7006A20.py pysense/lib/ + # pycoproc + cp shields/lib/pycoproc_1.py pysense/lib/ + # example + cp shields/pysense_1.py pysense/main.py + + zip -r pysense.zip pysense + +pysense2: + rm -rf pysense2 + rm -f pysense2.zip + @echo "Making Pysense 2" + mkdir pysense2 + mkdir pysense2/lib + # sensors + cp shields/lib/LIS2HH12.py pysense2/lib/ + cp shields/lib/LTR329ALS01.py pysense2/lib/ + cp shields/lib/MPL3115A2.py pysense2/lib/ + cp shields/lib/SI7006A20.py pysense2/lib/ + # pycoproc + cp shields/lib/pycoproc_2.py pysense2/lib/ + # example + cp shields/pysense_2.py pysense2/main.py + + zip -r pysense2.zip pysense2 + +pytrack: + rm -rf pytrack + rm -f pytrack.zip + @echo "Making Pytrack" + mkdir pytrack + mkdir pytrack/lib + #sensors + cp shields/lib/L76GNSS.py pytrack/lib/ + cp shields/lib/LIS2HH12.py pytrack/lib/ + #pycoproc + cp shields/lib/pycoproc_1.py pytrack/lib/ + #example + cp shields/pytrack_1.py pytrack/main.py + + zip -r pytrack.zip pytrack + +pytrack2: + rm -rf pytrack2 + rm -f pytrack2.zip + @echo "Making Pytrack2" + mkdir pytrack2 + mkdir pytrack2/lib + #sensors + cp shields/lib/L76GNSS.py pytrack2/lib/ + cp shields/lib/LIS2HH12.py pytrack2/lib/ + #pycoproc + cp shields/lib/pycoproc_2.py pytrack2/lib/ + #example + cp shields/pytrack_2.py pytrack2/main.py + + zip -r pytrack2.zip pytrack2 + +clean: + @echo "Cleaning up files" + rm -rf pyscan + rm -rf pysense + rm -rf pysense2 + rm -rf pytrack + rm -rf pytrack2 + + rm -f pyscan.zip + rm -f pysense.zip + rm -f pysense2.zip + rm -f pytrack.zip + rm -f pytrack2.zip \ No newline at end of file diff --git a/shields/pyscan_1.py b/shields/pyscan_1.py index 66ab94e..9e9c263 100644 --- a/shields/pyscan_1.py +++ b/shields/pyscan_1.py @@ -1,86 +1,114 @@ ''' Simple Pyscan NFC / MiFare Classic Example -Copyright (c) 2020, Pycom Limited. +Copyright (c) 2019, Pycom Limited. -This example runs the NFC discovery loop in a thread. -If a card is detected it will read the UID and compare it to VALID_CARDS -RGB LED is BLUE while waiting for card, -GREEN if card is valid, RED if card is invalid +This example continuously sends a REQA for ISO14443A card type +If a card is discovered, it will read the UID +If DECODE_CARD = True, will attempt to authenticate with CARDkey +If authentication succeeds will attempt to read sectors from the card ''' -DEBUG = False # change to True to see debug messages - from pycoproc_1 import Pycoproc from MFRC630 import MFRC630 from LIS2HH12 import LIS2HH12 from LTR329ALS01 import LTR329ALS01 -import binascii import time import pycom -import _thread +#add your card UID here VALID_CARDS = [[0x43, 0x95, 0xDD, 0xF8], [0x43, 0x95, 0xDD, 0xF9], [0x46, 0x5A, 0xEB, 0x7D, 0x8A, 0x08, 0x04]] + +# This is the default key for an unencrypted MiFare card +CARDkey = [ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ] +DECODE_CARD = False + py = Pycoproc(Pycoproc.PYSCAN) nfc = MFRC630(py) lt = LTR329ALS01(py) li = LIS2HH12(py) +pybytes_enabled = False +if 'pybytes' in globals(): + if(pybytes.isconnected()): + print('Pybytes is connected, sending signals to Pybytes') + pybytes_enabled = True + RGB_BRIGHTNESS = 0x8 RGB_RED = (RGB_BRIGHTNESS << 16) RGB_GREEN = (RGB_BRIGHTNESS << 8) RGB_BLUE = (RGB_BRIGHTNESS) +counter = 0 + +def check_uid(uid, len): + return VALID_CARDS.count(uid[:len]) + +def send_sensor_data(name, timeout): + if(pybytes_enabled): + while(True): + pybytes.send_signal(2, lt.light()) + pybytes.send_signal(3, li.acceleration()) + time.sleep(timeout) + # Make sure heartbeat is disabled before setting RGB LED pycom.heartbeat(False) # Initialise the MFRC630 with some settings nfc.mfrc630_cmd_init() -def check_uid(uid, len): - return VALID_CARDS.count(uid[:len]) - -def print_debug(msg): - if DEBUG: - print(msg) - -def send_sensor_data(name, timeout): - while(True): - print(lt.light()) - print(li.acceleration()) - time.sleep(timeout) - -def discovery_loop(nfc, id): - while True: - # Send REQA for ISO14443A card type - print_debug('Sending REQA for ISO14443A card type...') - atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA) - print_debug('Response: {}'.format(atqa)) - if (atqa != 0): - # A card has been detected, read UID - print_debug('A card has been detected, read UID...') - uid = bytearray(10) - uid_len = nfc.mfrc630_iso14443a_select(uid) - print_debug('UID has length: {}'.format(uid_len)) - if (uid_len > 0): - print_debug('Checking if card with UID: [{:s}] is listed in VALID_CARDS...'.format(binascii.hexlify(uid[:uid_len],' ').upper())) +print('Scanning for cards') +while True: + # Send REQA for ISO14443A card type + atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA) + if (atqa != 0): + # A card has been detected, read UID + print('A card has been detected, reading its UID ...') + uid = bytearray(10) + uid_len = nfc.mfrc630_iso14443a_select(uid) + print('UID has length {}'.format(uid_len)) + if (uid_len > 0): + # A valid UID has been detected, print details + counter += 1 + print("%d\tUID [%d]: %s" % (counter, uid_len, nfc.format_block(uid, uid_len))) + if DECODE_CARD: + # Try to authenticate with CARD key + nfc.mfrc630_cmd_load_key(CARDkey) + for sector in range(0, 16): + if (nfc.mfrc630_MF_auth(uid, nfc.MFRC630_MF_AUTH_KEY_A, sector * 4)): + pycom.rgbled(RGB_GREEN) + # Authentication was sucessful, read card data + readbuf = bytearray(16) + for b in range(0, 4): + f_sect = sector * 4 + b + len = nfc.mfrc630_MF_read_block(f_sect, readbuf) + print("\t\tSector %s: Block: %s: %s" % (nfc.format_block([sector], 1), nfc.format_block([b], 1), nfc.format_block(readbuf, len))) + else: + print("Authentication denied for sector %s!" % nfc.format_block([sector], 1)) + pycom.rgbled(RGB_RED) + # It is necessary to call mfrc630_MF_deauth after authentication + # Although this is also handled by the reset / init cycle + nfc.mfrc630_MF_deauth() + else: + #check if card uid is listed in VALID_CARDS if (check_uid(list(uid), uid_len)) > 0: - print_debug('Card is listed, turn LED green') + print('Card is listed, turn LED green') pycom.rgbled(RGB_GREEN) + if(pybytes_enabled): + pybytes.send_signal(1, ('Card is listed', uid)) else: - print_debug('Card is not listed, turn LED red') + print('Card is not listed, turn LED red') pycom.rgbled(RGB_RED) - else: - # No card detected - print_debug('Did not detect any card...') - pycom.rgbled(RGB_BLUE) - nfc.mfrc630_cmd_reset() - time.sleep(.5) - nfc.mfrc630_cmd_init() - -# This is the start of our main execution... start the thread -_thread.start_new_thread(discovery_loop, (nfc, 0)) -_thread.start_new_thread(send_sensor_data, ('Thread 2', 10)) + if(pybytes_enabled): + pybytes.send_signal(1, ('Unauthorized card detected', uid)) + + else: + pycom.rgbled(RGB_BLUE) + # We could go into power saving mode here... to be investigated + nfc.mfrc630_cmd_reset() + time.sleep(.5) + # Re-Initialise the MFRC630 with settings as these got wiped during reset + nfc.mfrc630_cmd_init() diff --git a/shields/pyscan_1_nfc.py b/shields/pyscan_1_nfc.py deleted file mode 100644 index 6b2ea36..0000000 --- a/shields/pyscan_1_nfc.py +++ /dev/null @@ -1,75 +0,0 @@ -''' -Simple Pyscan NFC / MiFare Classic Example -Copyright (c) 2019, Pycom Limited. - -This example continuously sends a REQA for ISO14443A card type -If a card is discovered, it will read the UID -If DECODE_CARD = True, will attempt to authenticate with CARDkey -If authentication succeeds will attempt to read sectors from the card -''' - -from pycoproc_1 import Pycoproc -from MFRC630 import MFRC630 -import time -import pycom - -# This is the default key for an unencrypted MiFare card -CARDkey = [ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ] -DECODE_CARD = False - -py = Pycoproc(Pycoproc.PYSCAN) -nfc = MFRC630(py) - -RGB_BRIGHTNESS = 0x8 - -RGB_RED = (RGB_BRIGHTNESS << 16) -RGB_GREEN = (RGB_BRIGHTNESS << 8) -RGB_BLUE = (RGB_BRIGHTNESS) - -counter = 0 - -# Make sure heartbeat is disabled before setting RGB LED -pycom.heartbeat(False) - -# Initialise the MFRC630 with some settings -nfc.mfrc630_cmd_init() - -while True: - # Send REQA for ISO14443A card type - atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA) - if (atqa != 0): - # A card has been detected, read UID - uid = bytearray(10) - uid_len = nfc.mfrc630_iso14443a_select(uid) - if (uid_len > 0): - # A valid UID has been detected, print details - counter += 1 - print("%d\tUID [%d]: %s" % (counter, uid_len, nfc.format_block(uid, uid_len))) - if DECODE_CARD: - # Try to authenticate with CARD key - nfc.mfrc630_cmd_load_key(CARDkey) - for sector in range(0, 16): - if (nfc.mfrc630_MF_auth(uid, nfc.MFRC630_MF_AUTH_KEY_A, sector * 4)): - pycom.rgbled(RGB_GREEN) - # Authentication was sucessful, read card data - readbuf = bytearray(16) - for b in range(0, 4): - f_sect = sector * 4 + b - len = nfc.mfrc630_MF_read_block(f_sect, readbuf) - print("\t\tSector %s: Block: %s: %s" % (nfc.format_block([sector], 1), nfc.format_block([b], 1), nfc.format_block(readbuf, len))) - else: - print("Authentication denied for sector %s!" % nfc.format_block([sector], 1)) - pycom.rgbled(RGB_RED) - # It is necessary to call mfrc630_MF_deauth after authentication - # Although this is also handled by the reset / init cycle - nfc.mfrc630_MF_deauth() - else: - # If we're not trying to authenticate, show green when a UID > 0 has been detected - pycom.rgbled(RGB_GREEN) - else: - pycom.rgbled(RGB_BLUE) - # We could go into power saving mode here... to be investigated - nfc.mfrc630_cmd_reset() - time.sleep(.5) - # Re-Initialise the MFRC630 with settings as these got wiped during reset - nfc.mfrc630_cmd_init() diff --git a/shields/pyscan_1_pybytes.py b/shields/pyscan_1_pybytes.py deleted file mode 100644 index 458b743..0000000 --- a/shields/pyscan_1_pybytes.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2019, Pycom Limited. -# -# This software is licensed under the GNU GPL version 3 or any -# later version, with permitted additional terms. For more information -# see the Pycom Licence v1.0 document supplied with this file, or -# available at https://www.pycom.io/opensource/licensing -# - -''' -Simple Pyscan NFC / MiFare Classic Example -Copyright (c) 2019, Pycom Limited. -This example runs the NFC discovery loop in a thread. -If a card is detected it will read the UID and compare it to VALID_CARDS -RGB LED is BLUE while waiting for card, -GREEN if card is valid, RED if card is invalid -''' - -DEBUG = False # change to True to see debug messages - -from pycoproc_1 import Pycoproc -from MFRC630 import MFRC630 -from LIS2HH12 import LIS2HH12 -from LTR329ALS01 import LTR329ALS01 -import binascii -import time -import pycom -import _thread - -VALID_CARDS = [[0x43, 0x95, 0xDD, 0xF8], - [0x43, 0x95, 0xDD, 0xF9]] - -py = Pycoproc(Pycoproc.PYSENSE) -nfc = MFRC630(py) -lt = LTR329ALS01(py) -li = LIS2HH12(py) - -RGB_BRIGHTNESS = 0x8 - -RGB_RED = (RGB_BRIGHTNESS << 16) -RGB_GREEN = (RGB_BRIGHTNESS << 8) -RGB_BLUE = (RGB_BRIGHTNESS) - -# Make sure heartbeat is disabled before setting RGB LED -pycom.heartbeat(False) - -# Initialise the MFRC630 with some settings -nfc.mfrc630_cmd_init() - -def check_uid(uid, len): - return VALID_CARDS.count(uid[:len]) - -def print_debug(msg): - if DEBUG: - print(msg) - -def send_sensor_data(name, timeout): - while(pybytes): - pybytes.send_signal(2, lt.light()) - pybytes.send_signal(3, li.acceleration()) - time.sleep(timeout) - -def discovery_loop(arg1, arg2): - while(pybytes): - # Send REQA for ISO14443A card type - print_debug('Sending REQA for ISO14443A card type...') - atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA) - print_debug('Response: {}'.format(atqa)) - if (atqa != 0): - # A card has been detected, read UID - print_debug('A card has been detected, read UID...') - uid = bytearray(10) - uid_len = nfc.mfrc630_iso14443a_select(uid) - print_debug('UID has length: {}'.format(uid_len)) - if (uid_len > 0): - print_debug('Checking if card with UID: [{:s}] is listed in VALID_CARDS...'.format(binascii.hexlify(uid[:uid_len],' ').upper())) - if (check_uid(list(uid), uid_len)) > 0: - print_debug('Card is listed, turn LED green') - pycom.rgbled(RGB_GREEN) - pybytes.send_signal(1, ('Card is listed, Access granted', uid)) - else: - print_debug('Card is not listed, turn LED red') - pycom.rgbled(RGB_RED) - pybytes.send_signal(1, ('Card is not listed, Access denied', uid)) - else: - # No card detected - print_debug('Did not detect any card...') - pycom.rgbled(RGB_BLUE) - pybytes.send_signal(1, ('Did not detect any card', 0)) - nfc.mfrc630_cmd_reset() - time.sleep(5) - nfc.mfrc630_cmd_init() - - -# This is the start of our main execution... start the thread -_thread.start_new_thread(discovery_loop, (nfc, 0)) -_thread.start_new_thread(send_sensor_data, ('Thread 2',10)) diff --git a/shields/pysense_1.py b/shields/pysense_1.py index 0a0d4b1..2a4e126 100644 --- a/shields/pysense_1.py +++ b/shields/pysense_1.py @@ -25,13 +25,18 @@ py = Pycoproc(Pycoproc.PYSENSE) +pybytes_enabled = False +if 'pybytes' in globals(): + if(pybytes.isconnected()): + print('Pybytes is connected, sending signals to Pybytes') + pybytes_enabled = True + mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals print("MPL3115A2 temperature: " + str(mp.temperature())) print("Altitude: " + str(mp.altitude())) mpp = MPL3115A2(py,mode=PRESSURE) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters print("Pressure: " + str(mpp.pressure())) - si = SI7006A20(py) print("Temperature: " + str(si.temperature())+ " deg C and Relative Humidity: " + str(si.humidity()) + " %RH") print("Dew point: "+ str(si.dew_point()) + " deg C") @@ -47,8 +52,20 @@ print("Roll: " + str(li.roll())) print("Pitch: " + str(li.pitch())) -print("Battery voltage: " + str(py.read_battery_voltage())) +# set your battery voltage limits here +vmax = 4.2 +vmin = 3.3 +battery_voltage = py.read_battery_voltage() +battery_percentage = (battery_voltage - vmin / (vmax - vmin))*100 +print("Battery voltage: " + str(py.read_battery_voltage()), " percentage: ", battery_percentage) +if(pybytes_enabled): + pybytes.send_signal(1, mpp.pressure()) + pybytes.send_signal(2, si.temperature()) + pybytes.send_signal(3, lt.light()) + pybytes.send_signal(4, li.acceleration()) + pybytes.send_battery_level(int(battery_percentage)) + print("Sent data to pybytes") -time.sleep(3) +time.sleep(5) py.setup_sleep(10) py.go_to_sleep() diff --git a/shields/pysense_1_pybytes.py b/shields/pysense_1_pybytes.py deleted file mode 100644 index 2d3326d..0000000 --- a/shields/pysense_1_pybytes.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2019, Pycom Limited. -# -# This software is licensed under the GNU GPL version 3 or any -# later version, with permitted additional terms. For more information -# see the Pycom Licence v1.0 document supplied with this file, or -# available at https://www.pycom.io/opensource/licensing -# - -# See https://docs.pycom.io for more information regarding library specifics - -from pycoproc_1 import Pycoproc -from LIS2HH12 import LIS2HH12 -from SI7006A20 import SI7006A20 -from LTR329ALS01 import LTR329ALS01 -from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE - -py = Pycoproc(Pycoproc.PYSENSE) -mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals -si = SI7006A20(py) -lt = LTR329ALS01(py) -li = LIS2HH12(py) - -import _thread -from time import sleep -import uos - -def send_sensor_data(): - h2 = None - t2 = None - l2 = None - while (pybytes): - h = round(si.humidity(),1) - t = round(si.temperature(),1) - l = lt.light() - if h != h2: - print('humidity', h) - pybytes.send_signal(1, h) - h2=h - if t != t2: - print('temperature', t) - pybytes.send_signal(2, t) - t2=t - if l != l2: - print('luminocity', l) - pybytes.send_signal(3, l) - l2=l - sleep(10) - -# _thread.start_new_thread(send_sensor_data, ()) -send_sensor_data() diff --git a/shields/pysense_2.py b/shields/pysense_2.py index c7e1697..28495a1 100644 --- a/shields/pysense_2.py +++ b/shields/pysense_2.py @@ -27,6 +27,12 @@ if py.read_product_id() != Pycoproc.USB_PID_PYSENSE: raise Exception('Not a Pysense') +pybytes_enabled = False +if 'pybytes' in globals(): + if(pybytes.isconnected()): + print('Pybytes is connected, sending signals to Pybytes') + pybytes_enabled = True + mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals print("MPL3115A2 temperature: " + str(mp.temperature())) print("Altitude: " + str(mp.altitude())) @@ -50,3 +56,17 @@ print("Pitch: " + str(li.pitch())) print("Battery voltage: " + str(py.read_battery_voltage())) + +# set your battery voltage limits here +vmax = 4.2 +vmin = 3.3 +battery_voltage = py.read_battery_voltage() +battery_percentage = (battery_voltage - vmin / (vmax - vmin))*100 +print("Battery voltage: " + str(py.read_battery_voltage()), " percentage: ", battery_percentage) +if(pybytes_enabled): + pybytes.send_signal(1, mpp.pressure()) + pybytes.send_signal(2, si.temperature()) + pybytes.send_signal(3, lt.light()) + pybytes.send_signal(4, li.acceleration()) + pybytes.send_battery_level(int(battery_percentage)) + print("Sent data to pybytes") \ No newline at end of file diff --git a/shields/pytrack_1.py b/shields/pytrack_1.py index 4751617..cab1cb9 100644 --- a/shields/pytrack_1.py +++ b/shields/pytrack_1.py @@ -34,6 +34,12 @@ py = Pycoproc(Pycoproc.PYTRACK) l76 = L76GNSS(py, timeout=30) +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') @@ -42,3 +48,13 @@ coord = l76.coordinates() #f.write("{} - {}\n".format(coord, rtc.now())) print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free())) + if(pybytes_enabled): + pybytes.send_signal(1, coord) + time.sleep(10) + +""" +# sleep procedure +time.sleep(3) +py.setup_sleep(10) +py.go_to_sleep() +""" diff --git a/shields/pytrack_1_pybytes.py b/shields/pytrack_1_pybytes.py deleted file mode 100644 index 51e03ab..0000000 --- a/shields/pytrack_1_pybytes.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2019, Pycom Limited. -# -# This software is licensed under the GNU GPL version 3 or any -# later version, with permitted additional terms. For more information -# see the Pycom Licence v1.0 document supplied with this file, or -# available at https://www.pycom.io/opensource/licensing -# - -import machine -import math -import network -import os -import time -import utime -from machine import RTC -from machine import SD -from machine import Timer -from L76GNSS import L76GNSS -from pycoproc_1 import Pycoproc -from LIS2HH12 import LIS2HH12 -# setup as a station - -import gc - -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 = Pycoproc(Pycoproc.PYTRACK) -l76 = L76GNSS(py, timeout=30) -chrono = Timer.Chrono() -chrono.start() -li = LIS2HH12(py) -#sd = SD() -#os.mount(sd, '/sd') -#f = open('/sd/gps-record.txt', 'w') -while (pybytes): - coord = l76.coordinates() - #f.write("{} - {}\n".format(coord, rtc.now())) - print('Sending data', coord) - pybytes.send_signal(1, coord) - pybytes.send_signal(2, li.acceleration()) - time.sleep(10) diff --git a/shields/pytrack_2.py b/shields/pytrack_2.py index 8627e22..52fe547 100644 --- a/shields/pytrack_2.py +++ b/shields/pytrack_2.py @@ -42,15 +42,23 @@ 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): -for _ in range(5): +while (True): coord = l76.coordinates() #f.write("{} - {}\n".format(coord, rtc.now())) print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free())) + if(pybytes_enabled): + pybytes.send_signal(1, coord) + time.sleep(10) """ # sleep procedure