#!/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)
