예제 #1
0
    def run_deepsleep(self):

        if not self.run():
            # RTC wasn't set, try to sleep forever
            self.rtc.alarm(time=2000000000)

        # Set the wakeup (why do it earlier?)
        rtc_i = self.rtc.irq(trigger=RTC.ALARM0, wake=DEEPSLEEP)

        self.log("Going to sleep, waking in %dms" % self.rtc.alarm_left())

        # Close files on the SD card
        if self.sd:
            self.logfile.close()
            self.logfile = None
            unmount('/sd')
            self.sd.deinit()

        # Turn the screen off
        self.epd.disable()

        if not self.wifi_pin():
            # Basically turn off
            deepsleep()
        else:
            self.log("DEBUG MODE: Staying awake")
            pass
예제 #2
0
def save_header():
    """
    Function to write header to data file in SD. Header contains the following
    values:
    device_id, deployment, datetime, latitude, longitude, altitude, hdop,
    voltage and data_sent.
    """
    sd = sd_access()
    f_test = False

    try:
        f_test = open(data_filename, 'r')
    except OSError as e:
        print("Error: {}. Data file not found".format(e))

    if f_test is False:
        _write_data()
        f = open(data_filename, 'a')
        header = "{},{},{},{},{},{},{},{},{},\n".format(
            "#device_id", "deployment", "datetime", "latitude", "longitude",
            "altitude", "hdop", "voltage", "data_sent")
        f.write(header)
        f.close()

    sd.deinit()
    os.unmount(sd_mount_dir)
예제 #3
0
    def log_stop(self, stop_exception):
        if stop_exception:
            stop_out = uio.StringIO()

            print(">" * 80, file=stop_out)
            print(" Stopped at " + str(time.localtime()[:6]), file=stop_out)
            print("-" * 80, file=stop_out)

            if stop_exception:
                print("Exception: ", file=stop_out)
                sys.print_exception(stop_exception, stop_out) # pylint: disable=E1101
                print("-" * 80, file=stop_out)

            print(str(self.gps_poller), end='', file=stop_out)
            print("<" * 80, file=stop_out)

            stop_msg = stop_out.getvalue()

            try:
                with open("/sd/stoplog.txt", "a+") as fh:
                    print(stop_msg, file=fh)
            except:
                pass

            if self.stdout_echo:
                print(stop_msg)

        try:
            os.unmount("/sd") # pylint: disable=E1101
            print("** Unmounted /sd")
        except:
            pass
예제 #4
0
파일: tools.py 프로젝트: widget/iot-display
def print_log(path='/sd/display.log'):
    sd = SD()
    os.mount(sd, '/sd')

    with open(path, 'r') as logfile:
        for line in logfile:
            print(line, end='')

    os.unmount('/sd')
    sd.deinit()
예제 #5
0
def save_data(device_id=None,
              deployment=None,
              datetime=None,
              lat=None,
              lon=None,
              alt=None,
              hdop=None,
              volt=None,
              data_sent=None):
    """
    Function to save data file in SD. Data contains the following
    values:
    device_id, deployment, datetime, lat, lon, alt, hdop, volt and data_sent.

    Parameters
    ----------
        device_id: string
            the id of the prototype
        deployment: string
            the deployment sequence of the measurement
        datetime: tuple
            tuple that contains the real time clock
        lat: float
            latitude from gps
        lon: float
            longitude from gps
        alt: int
            altitude from gps
        hdop: int
            hdop (quality data) from gps
        volt: int
            voltage from battery
        data_sent: bool
            True if data has been sent to Sigfox

    """

    sd = sd_access()
    f = open(data_filename, 'a')

    date_std = "{}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}.{}+00:00".format(
        datetime[0], datetime[1], datetime[2], datetime[3], datetime[4],
        datetime[5], datetime[6])

    data = "{},{},{},{},{},{},{},{},{},\n".format(device_id, deployment,
                                                  date_std, lat, lon, alt,
                                                  hdop, volt, data_sent)

    f.write(data)

    f.close()
    sd.deinit()
    os.unmount(sd_mount_dir)
예제 #6
0
파일: tools.py 프로젝트: widget/iot-display
def save_config(cfg):
    """
    Save out a configuration file
    :param Config cfg: config option
    :return: None
    """
    sd = SD()
    os.mount(sd, '/sd')

    with open("/sd/config.txt", "w") as cfgfile:
        cfgfile.write("Host:%s\n", cfg.host)
        cfgfile.write("WiFi:%s\n", cfg.wifi_ssid)
        cfgfile.write("Pass:%s\n", cfg.wifi_key)
        cfgfile.write("Port:%s\n", cfg.port)
        cfgfile.write("Image:%s\n", cfg.image_path)
        cfgfile.write("Meta:%s\n", cfg.metadata_path)
        if cfg.upload_path:
            cfgfile.write("Up:%s\n", cfg.upload_path)
    os.unmount(sd)
    sd.deinit()
예제 #7
0
def get_deployment_seq():
    """
    Function to get the sequence deployment from deployment file.
    It updates the character sequence from deployment file adding 1 to the
    sequence. I.e.: a + 1 => b

    Returns
    -------
        deployment: string
            character sequence from deployment.txt
    """
    deployment = None

    sd = sd_access()
    f_read = False

    try:
        f_read = open(deployment_filename, 'r')
        deployment = f_read.readall()
        f_read.close()
    except OSError as e:
        print("Error: {}. Deployment file not found".format(e))

    if f_read is False:
        deployment = "a"
        _write_deployment()

    if deployment is None or deployment is '' or (ord(deployment) < 97) or \
       (ord(deployment) > 122):
        deployment = "a"
        _write_deployment()

    f_write = open(deployment_filename, 'w')
    next_deployment = chr(ord(deployment) + 1)
    f_write.write("{}".format(next_deployment))
    f_write.close()

    sd.deinit()
    os.unmount(sd_mount_dir)

    return deployment
예제 #8
0
    def load(debug=False, sd=None):
        """
         Load off SD our AP, pw, and URL details
        :param debug: Logging
        :param sd: SD object if mounted already
        :return: Config object
        """
        from machine import SD
        cfg = None
        try:
            unmount = False
            if sd is None:
                sd = SD()
                os.mount(sd, '/sd')
                unmount = True

            cfg = Config.load_file(open(Config.SD_CONFIG_PATH,"r"), debug)

            if unmount:
                try:
                    os.unmount('/sd') # got renamed in upy 1.9
                except AttributeError:
                    os.umount('/sd')
                sd.deinit()
                del sd
        except OSError:
            print("Can't open config file SD card")

        if not cfg:
            cfg = Config.load_file(open(Config.FLASH_CONFIG_PATH, "r"), debug)
            if not cfg:
                raise ValueError("No config file!")
            print("Loaded from flash")
            cfg.src = "flash"
        else:
            print("Loaded from SD card")
            cfg.src = "sd"
        return cfg
예제 #9
0
print('CC3200' in os.uname().machine)
print('WiPy' == os.uname().sysname)

os.sync()
os.stat('/flash')
os.stat('/flash/sys')
os.stat('/flash/boot.py')
os.stat('/sd')
os.stat('/')
os.chdir('/sd/test')
os.remove('test.txt')
os.chdir('/sd')
os.rmdir('test')
os.listdir('/sd')
print(os.listdir('/'))
os.unmount('/sd')
print(os.listdir('/'))
os.mkfs(sd)
os.mount(sd, '/sd')
print(os.listdir('/'))
os.chdir('/flash')

# next ones must raise
sd.deinit()
try:
    os.listdir('/sd')
except:
    print('Exception')

#re-initialization must work
sd.init()
예제 #10
0
파일: os.py 프로젝트: jlillest/micropython
print('CC3200' in os.uname().machine)
print('WiPy' == os.uname().sysname)

os.sync()
os.stat('/flash')
os.stat('/flash/sys')
os.stat('/flash/boot.py')
os.stat('/sd')
os.stat('/')
os.chdir('/sd/test')
os.remove('test.txt')
os.chdir('/sd')
os.rmdir('test')
os.listdir('/sd')
print(os.listdir('/'))
os.unmount('/sd')
print(os.listdir('/'))
os.mkfs(sd)
os.mount(sd, '/sd')
print(os.listdir('/'))
os.chdir('/flash')

# next ones must raise
sd.deinit()
try:
    os.listdir('/sd')
except:
    print('Exception')

#re-initialization must work
sd.init()
예제 #11
0
capteur_BME280 = BME280(BME280_I2C_ADR, bus_i2c)
capteur_BME280.Calibration_Param_Load()

sd = SD()
os.mount(sd, '/sd')

# ouverture en ecriture : 'w'
f = open('/sd/info.csv', 'w')
#ecriture d une chaine de caractere
f.write('AA;MM;JJ;HH;MM;SS;temp;humi;pres\r\n')

count = 0
rtc = RTC()
rtc.init((2020, 3, 10, 15, 0, 0, 0, 0))
# rtc.ntp_sync("pool.ntp.org")

while (count < 5):
    print(rtc.now())
    print(rtc.now()[0])
    print(rtc.now()[1])

    f.write("%d;%d;%d;%d;%d;%d;%.2f;%.2f;%.2f\r\n" %
            (rtc.now()[0], rtc.now()[1], rtc.now()[2], rtc.now()[3],
             rtc.now()[4], rtc.now()[5], capteur_BME280.read_temp(),
             capteur_BME280.read_humidity(), capteur_BME280.read_pression()))
    time.sleep(1)
    count += 1

f.close()
os.unmount('/sd')
예제 #12
0
print("CC3200" in os.uname().machine)
print("WiPy" == os.uname().sysname)

os.sync()
os.stat("/flash")
os.stat("/flash/sys")
os.stat("/flash/boot.py")
os.stat("/sd")
os.stat("/")
os.chdir("/sd/test")
os.remove("test.txt")
os.chdir("/sd")
os.rmdir("test")
os.listdir("/sd")
print(os.listdir("/"))
os.unmount("/sd")
print(os.listdir("/"))
os.mkfs(sd)
os.mount(sd, "/sd")
print(os.listdir("/"))
os.chdir("/flash")

# next ones must raise
sd.deinit()
try:
    os.listdir("/sd")
except:
    print("Exception")

# re-initialization must work
sd.init()
예제 #13
0
msg = '{:2.1f},{:3.1f},{:2.3f},{:2.3f},{:2.3f},{:2.3f},{:2.3f}'.format(
    hih.temperature, hih.humidity, vPanel.voltage, vPyra.voltage,
    vBatt.voltage, vBiasP.voltage, vBiasB.voltage)

if logData:
    try:
        print('Saving data to SD card...')
        # SD instantiation
        sd = SD()
        mount(sd, '/sd')
        # Filename pattern: aaaammdd.csv
        with open('/sd/' + timestamp.split(' ')[0].replace('-', '') + '.csv',
                  'a') as datafile:
            datafile.write(timestamp + ',' + msg + '\n')
            datafile.close()
        unmount('/sd')
    except:
        print('Error while saving data')

# Enter deep-sleep mode to save power
if enableSleep:
    print(rtc.getDatetime())
    sleepParams = rtc.readLastSyncedSleepParams()
    if (rtc.now()[3:6] >= sleepParams[:3]):
        print('Good night!')
        deepsleep(sleepParams[3])
    # Record time elapsed from start time
    t = time() - tStart
    # Sleep until completing 60 seconds from start time
    if t < samplingInterval:
        print('Sleeping...')
예제 #14
0
파일: os.py 프로젝트: 19emtuck/micropython
print('CC3200' in os.uname().machine)
print('WiPy' == os.uname().sysname)

os.sync()
os.stat('/flash')
os.stat('/flash/sys')
os.stat('/flash/boot.py')
os.stat('/sd')
os.stat('/')
os.chdir('/sd/test')
os.remove('test.txt')
os.chdir('/sd')
os.rmdir('test')
os.listdir('/sd')
print(os.listdir('/'))
os.unmount('/sd')
print(os.listdir('/'))
os.mkfs(sd)
os.mount(sd, '/sd')
print(os.listdir('/'))
os.chdir('/flash')

# next ones must raise
sd.deinit()
try:
    os.listdir('/sd')
except:
    print('Exception')

#re-initialization must work
sd.init()