Merge branch 'publish' into pysense2-pytrack2

This commit is contained in:
gijsio
2020-08-11 17:48:46 +02:00
62 changed files with 914 additions and 482 deletions

View File

@@ -19,4 +19,12 @@ print("\n") #feed a new line
print("\t tabbed in")
#you can specify a variable into the string as well!
print("hello world: " + str(machine.rng()) + " random number" )
#or use format
print("hello world: {} {}".format(machine.rng(), " random number"))
#you can also ask for user input
result = input("what's up?\n")
print(result)
# and lastly, you can also print like this,which is very useful when printing large amounts of data
i = 10
print(1,2,3,'e',i)
```

View File

@@ -82,34 +82,4 @@ print("This will never be printed")
>Note: Using `deepsleep()` will also stop the USB connection. Be wary of that when trying to upload new code to the device!
#### Other methods
The expansionboards (Pysense 2.0 X, and Pytrack 2.0 X, DeepSleep shield) use a different mechanism to put the controller to sleep. A separate controller on the expansion board will put the main controller to sleep. This will actually cut all power from the module for the set amount of time, hard resetting it. Cutting power to the expansion board will work as well. Using this method, we can still recover the wake up reason and remaining sleep time. The example below works was written for a Pysense, but works on any of the boards by changing the first lines
```python
from pysense import Pysense
py = Pysense()
py.setup_sleep(10) # set sleep time of 10 seconds
py.go_to_sleep()
print("this will never be printed")
```
Using this method, we can also wake the board using the accelerometer and external pin `P6` by rising (`True`) or falling (`False`) edge
```python
from pysense import Pysense
from LIS2HH12 import LIS2HH12
py = Pysense()
acc = LIS2HH12()
# enable activity and also inactivity interrupts, using the default callback handler
py.setup_int_wake_up(True, True)
# set the acceleration threshold to 2000mG (2G) and the min duration to 200ms
acc.enable_activity_interrupt(2000, 200)
py.set_int_pin_wake_up(True) #wake up on rising edge on pin 6 of the expansion header
py.go_to_sleep()# the device will sleep indefinitely, until pin 6 goes high, or the accelerometer is triggered
```
LTE Power saving mode (PSM)
For the Pysense, Pytrack and Pyscan expansionboards, an additional sleep function is available. You can find out more about that [here](../expansionboards/sleep/)

View File

@@ -6,13 +6,18 @@ aliases:
- chapter/tutorials/expansionboards
disable_breadcrumbs: true
---
>Note: Before using the Pysense, Pytrack or Pyscan board, check the [GitHub](https://github.com/pycom/pycom-libraries) for the latest version of the libraries.
Make a folder inside your project folder and call it `lib`. Then, copy the appropiate libraries from the github repository to the folder. Always copy the `pysense.py`, `pytrack.py` or `pyscan.py` *and* `pycoproc.py` files if you want to use the boards' functions
>Note: Before using the Pysense, Pytrack and Pyscan boards, check the [GitHub](https://github.com/pycom/pycom-libraries) for the latest version of the libraries.
To use the Pysense, Pytrack or Pyscan, make a folder inside your project folder and call it `lib`. Then, copy the appropiate sensor libraries from the github repository to the folder. Always copy the `pysense.py` or `pytrack.py` and `pycoproc.py` files if you want to use the boards' functions. The `pycoproc.py` library also allows for a special sleep mode. An example for this is provided [here](../expansionboards/sleep/)
* [Pygate](../expansionboards/pygate/)
* [Pysense](../expansionboards/pysense/)
* [Pysense 2.0 X](../expansionboards/pysense2/)
* [Pytrack](../expansionboards/pytrack/)
* [Pytrack 2.0 X](../expansionboards/pytrack2/)
* [Pyscan](../expansionboards/pyscan/)
* [Pyscan](../expansionboards/pyscan/)
>Note: Make sure to click `upload to device` to be able to `import` the appropriate libraries in your code!

View File

@@ -101,7 +101,8 @@ buf = fp.read()
# Start the Pygate
machine.pygate_init(buf)
# disable degub messages
# machine.pygate_debug_level(1)
```
A sample `config.json` file for gateway configuration in EU868 region:

View File

@@ -6,6 +6,64 @@ aliases:
- chapter/tutorials/pysense
---
## All sensors
>Note: You can find this example in the [GitHub repository](https://github.com/pycom/pycom-libraries/tree/master/pysense). Over there, you can also find the relevant libraries.
```python
#!/usr/bin/env python
#
# Copyright (c) 2020, 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
import time
import pycom
from pysense import Pysense
import machine
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE
pycom.heartbeat(False)
pycom.rgbled(0x0A0A08) # white
py = Pysense()
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")
t_ambient = 24.4
print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(si.humid_ambient(t_ambient)) + "%RH")
lt = LTR329ALS01(py)
print("Light (channel Blue lux, channel Red lux): " + str(lt.light()))
li = LIS2HH12(py)
print("Acceleration: " + str(li.acceleration()))
print("Roll: " + str(li.roll()))
print("Pitch: " + str(li.pitch()))
print("Battery voltage: " + str(py.read_battery_voltage()))
time.sleep(3)
py.setup_sleep(10)
py.go_to_sleep()
```
## Accelerometer
This basic example shows how to read pitch and roll from the on-board accelerometer and output it in comma separated value (CSV) format over serial.
@@ -24,7 +82,7 @@ while True:
time.sleep_ms(100)
```
![](/gitbook/assets/accelerometer_visualiser.png)
If you want to visualise the data output by this script a Processing sketch is available [here](https://github.com/pycom/pycom-libraries/tree/master/examples/pytrack_pysense_accelerometer) that will show the board orientation in 3D.
>Note: Use [Processing](https://processing.org/) to visualize the orientation of your board using the example. You can find the Processing sketch [here](https://github.com/pycom/pycom-libraries/tree/master/examples/pytrack_pysense_accelerometer)
>
>![](/gitbook/assets/accelerometer_visualiser.png)

View File

@@ -0,0 +1,66 @@
---
title: "Pysense 2.0 X Examples"
aliases:
- tutorials/pysense.html
- tutorials/pysense.md
- chapter/tutorials/pysense
---
The Pysense 2.0 X has an external header that allows you to attach all kinds of sensors.
## All sensors
>Note: You can find this example in the [GitHub repository](https://github.com/pycom/pycom-libraries/tree/master/pysense-2). Over there, you can also find the relevant libraries.
```python
#!/usr/bin/env python
#
# Copyright (c) 2020, 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
import time
import pycom
from pysense import Pysense
import machine
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE
pycom.heartbeat(False)
pycom.rgbled(0x0A0A08) # white
py = Pysense()
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")
t_ambient = 24.4
print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(si.humid_ambient(t_ambient)) + "%RH")
lt = LTR329ALS01(py)
print("Light (channel Blue lux, channel Red lux): " + str(lt.light()))
li = LIS2HH12(py)
print("Acceleration: " + str(li.acceleration()))
print("Roll: " + str(li.roll()))
print("Pitch: " + str(li.pitch()))
print("Battery voltage: " + str(py.read_battery_voltage()))
# time.sleep(3)
# py.setup_sleep(10)
# py.go_to_sleep()
```

View File

@@ -7,11 +7,9 @@ aliases:
---
Both the Pysense and Pytrack use the same accelerometer. Please see the [Pysense Examples](../pysense) to see how to use the accelerometer.
>Note: You can find this example in the [GitHub repository](https://github.com/pycom/pycom-libraries/tree/master/pytrack). Over there, you can also find the relevant libraries.
>Note: You need to add the libraries from [here](https://github.com/pycom/pycom-libraries/tree/master/pytrack) in the `lib` folder of your project before the example will work. You can also find the example in there.
## Example
## GPS Example
```python

View File

@@ -0,0 +1,70 @@
---
title: "Pytrack 2.0 X Examples"
aliases:
- tutorials/pysense.html
- tutorials/pysense.md
- chapter/tutorials/pysense
---
The Pytrack 2.0 X has an external header that allows you to attach all kinds of sensors.
## All sensors
>Note: You can find this example in the [GitHub repository](https://github.com/pycom/pycom-libraries/tree/master/pytrack-2). Over there, you can also find the relevant libraries.
```python
#!/usr/bin/env python
#
# Copyright (c) 2020, 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
import gc
import pycom
from machine import RTC
from machine import SD
from L76GNSS import L76GNSS
from pytrack import Pytrack
pycom.heartbeat(False)
pycom.rgbled(0x0A0A08) # white
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()
time.sleep(1)
l76 = L76GNSS(py, timeout=30, buffer=512)
# sd = SD()
# os.mount(sd, '/sd')
# f = open('/sd/gps-record.txt', 'w')
# while (True):
for _ in range(5):
coord = l76.coordinates()
#f.write("{} - {}\n".format(coord, rtc.now()))
print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free()))
"""
# sleep procedure
time.sleep(3)
py.setup_sleep(10)
py.go_to_sleep()
"""
```

View File

@@ -0,0 +1,51 @@
---
title: 'Sleep'
---
The expansionboards (Pysense 2.0 X, and Pytrack 2.0 X, DeepSleep shield) use a different mechanism to put the controller to sleep. A separate controller on the expansion board will put the main controller to sleep. This will actually cut all power from the module for the set amount of time, hard resetting it. Cutting power to the expansion board will work as well. Using this method, we can still recover the wake up reason and remaining sleep time. The example below works was written for a Pysense, but works on any of the boards by changing the first lines
```python
from pysense import Pysense
py = Pysense()
py.setup_sleep(10) # set sleep time of 10 seconds
py.go_to_sleep()
print("this will never be printed")
```
Using this method, we can also wake the board using the accelerometer interrupt method:
```python
#from pytrack import Pytrack
from pysense import Pysense
from LIS2HH12 import LIS2HH12
import time
#py = Pytrack()
py = Pysense()
# display the reset reason code and the sleep remaining in seconds
# possible values of wakeup reason are:
# WAKE_REASON_ACCELEROMETER = 1
# WAKE_REASON_PUSH_BUTTON = 2
# WAKE_REASON_TIMER = 4
# WAKE_REASON_INT_PIN = 8
print("Wakeup reason: " + str(py.get_wake_reason()))
print("Approximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec")
time.sleep(0.5)
# enable wakeup source from INT pin
py.setup_int_pin_wake_up(False)
acc = LIS2HH12()
# enable activity and also inactivity interrupts, using the default callback handler
py.setup_int_wake_up(True, True)
# set the acceleration threshold to 2000mG (2G) and the min duration to 200ms
acc.enable_activity_interrupt(2000, 200)
# go to sleep for 5 minutes maximum if no accelerometer interrupt happens
py.setup_sleep(300)
py.go_to_sleep()
```

View File

@@ -6,8 +6,9 @@ aliases:
---
Using our devices, several different network protocols can be used. We have grouped them in different categories. Not all examples will work with every network. Generally, examples are compatible with different networks.
**Protecols**
**Protocols**
* [WiFi Sniffer](../networkprotocols/wifisniffer/)
* [HTTPS](../networkprotocols/https/)
* [MQTT](../networkprotocols/mqtt/)
* [NTP](../networkprotocols/ntp/)

View File

@@ -0,0 +1,7 @@
---
Title: 'HTTP Client'
---
In this example, we discuss how to access information served on the internet. Once you have connected to either WiFi or LTE, it is possible to access any webpage. Now there is no such thing as a webbrowser like Chrome or Firefox in your device, and the REPL is not that great at rendering webpages either, so we are mainly looking at the source of the page here.
For example, we can use the socket to render
...

View File

@@ -5,7 +5,30 @@ aliases:
- tutorials/all/https.md
- chapter/tutorials/all/https
---
Using HTTPS adds Transport Layer Security (TLS) to your network traffic. The advantage is an encrypted connection between your device and the server.
## Basic example
```python
from network import WLAN #note that you can also use LTE
import socket
import ssl
import time
wlan = WLAN()
wlan.init(mode=WLAN.STA, ssid='your ssid', auth=(WLAN.WPA2, 'your password'))
print("connecting", end='')
while not wlan.isconnected():
time.sleep(0.25)
print(".", end='')
print("connected")
print(wlan.ifconfig())
s = socket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
ss = ssl.wrap_socket(s) #adds TLS
ss.connect(socket.getaddrinfo('pycom.io', 443)[0][-1])
rec = ss.recv(4096)
print(rec)
```
Basic connection using `ssl.wrap_socket()`.
```python
@@ -15,6 +38,7 @@ import ssl
s = socket.socket()
ss = ssl.wrap_socket(s)
ss.connect(socket.getaddrinfo('www.google.com', 443)[0][-1])
ss.se
```
Below is an example using certificates with the blynk cloud.

View File

@@ -0,0 +1,16 @@
---
title: 'Networks'
---
The Pycom devices support several different types of networks.
We have the WiFi and Bluetooth connections:
* [WiFi](../networks/wifi/)
* [Bluetooth Low Energy](../networks/ble/)
* [LoRa](../networks/lora/)
* [Sigfox]( ../networks/sigfox/)
* [LTE](../networks/lte/)
* [Ethernet](../networks/ethernet/)
> If you are looking for examples on how to connect to different services, check [here](../networkprotocols/)

View File

@@ -4,6 +4,7 @@ aliases:
---
The following tutorials demonstrate the use of the LoRa functionality on the LoPy. LoRa can work in 2 different modes; **LoRa-MAC** (which we also call Raw-LoRa) and **LoRaWAN** mode.
> Note: LoRa will not work with Pygate firmware loaded on your device. It will return a `/event_groups.c:498 (xEventGroupClearBits)- assert failed!` error.
* **LoRaWAN mode** implements the full LoRaWAN stack for a class A device. It supports both OTAA and ABP connection methods, as well as advanced features like adding and removing custom channels to support "special" frequencies plans like the those used in New Zealand. There are two basic ways of accessing the LoraWAN network:
* [LoRaWAN ABP](../lora/lorawan-abp/)

View File

@@ -14,29 +14,34 @@ import time
import socket
lte = LTE()
lte.init()
#some carriers have special requirements, check print(lte.send_at_cmd("AT+SQNCTM=?")) to see if your carrier is listed.
#when using verizon, use
#lte.init(carrier=verizon)
#when usint AT&T use,
#lte.init(carrier=at&t)
#some carriers do not require an APN
#also, check the band settings, for some carriers they auto-configure.
#also, check the band settings with your carrier
lte.attach(band=20, apn="your apn")
print("attaching..",end='')
while not lte.isattached()
time.delay(0.25)
print('.')
print('.',end='')
print(lte.send_at_cmd('AT!="fsm"')) # get the System FSM
print("LTE modem attached!")
print("attached!")
lte.connect()
print("connecting [##",end='')
while not lte.isconnected():
time.sleep(0.25)
print('#')
print('#',end='')
#print(lte.send_at_cmd('AT!="showphy"'))
print(lte.send_at_cmd('AT!="fsm"'))
print("LTE modem connected!")
print("] connected!")
print(socket.getaddrinfo('pycom.io', 80))
lte.deinit()
#now we can safely machine.deepsleep()
```
@@ -44,10 +49,31 @@ The last line of the script should return a tuple containing the IP address of t
>Note: the first time, it can take a long while to attach to the network.
# LTE disconnecting
When the LTE disconnects in an unexpected situation, for example when the signal is lost, `lte.isconnected()` will still return `True`. Currently, there is a solution using the callback and handler function listed below:
```python
from network import LTE
import time
from sleep import sleep
import machine
def cb_handler(arg):
print("CB: LTE Coverage lost")
print("CB: sleep", s)
print("CB: deinit")
lte.deinit()
print("CB: reset")
machine.reset()
lte.lte_callback(LTE.EVENT_COVERAGE_LOSS, cb_handler)
```
# LTE Troubleshooting guide
Below, we review the responses from `print(lte.send_at_cmd('AT!="fsm"'))`. If you are having trouble attaching to the network, or getting a connection up and running, this might give some direction into what you are looking for. We are mainly looking at the status of the top two indicators for now.
1. Before calling `lte.attach()`, the status will be `STOPPED`.
```
SYSTEM FSM
==========
@@ -184,6 +210,7 @@ Below, we review the responses from `print(lte.send_at_cmd('AT!="fsm"'))`. If yo
| HP CAT FSM |IDLE |
+--------------------------+--------------------+
```
* Firmware version:
Use the following to check the version number:
```python