Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JiekangHuang/MicroPython-AM7020
MicroPython-AM7020
https://github.com/JiekangHuang/MicroPython-AM7020
Last synced: 3 months ago
JSON representation
MicroPython-AM7020
- Host: GitHub
- URL: https://github.com/JiekangHuang/MicroPython-AM7020
- Owner: JiekangHuang
- License: mit
- Created: 2021-03-16T06:13:54.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-03-29T09:01:43.000Z (over 3 years ago)
- Last Synced: 2024-07-05T02:05:20.694Z (4 months ago)
- Language: Python
- Size: 2.4 MB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micropython - MicroPython-AM7020 - MicroPython driver for AM7020 Narrowband Internet of Things (NBIoT) module. (Libraries / Communications)
README
# AM7020 MicroPython 範例程式碼
[AM7020](https://atticedu.com/index.php/am7020.html) (SIMCOM SIM7020E) 窄頻物聯網(NBIoT)模組 MicroPython 範例程式碼
![AM7020](images/am7020_front.jpg)Installation
------------To install am7020:
```python
import upip
upip.install('micropython-am7020')
```
or
```console
$ ampy -p COMX put am7020
```
## MQTT 教學說明
Declare nb and mqtt client instance using:
```Python
nb = AM7020NB(uart_num=0, baudrate=115200, tx_pin=16, rx_pin=17, reset_pin=5, dump_at_cmd=False)
mqtt = AM7020MQTT(nb)
```
Initialize nb and connect to NBIOT base station:
```Python
while((not nb.init() or (not nb.nbiotConnect(apn, band)))):
print(".")
while(not nb.waitForNetwork()):
print(".")
sleep(5)
```
Check MQTT connection status and connect to Broker:
```Python
if(not mqtt.chkConnBroker()):
mqtt.connBroker(MQTT_BROKER, 1883, mqtt_id="MY_AM7020_TEST_MQTTID")
```
Publish and subscribe:
```Python
mqtt.publish(TEST_TOPIC, "Hello MQTT")
def callback1(msg):
print(TEST_TOPIC, ":", msg)
mqtt.subscribe(TEST_TOPIC, callback1)
```
Listen for messages from the broker:
```Python
mqtt.procSubs()
```
## HTTP 教學說明
Declare nb and http client instance using:
```Python
nb = AM7020NB(uart_num=0, baudrate=115200, tx_pin=16, rx_pin=17, reset_pin=5, dump_at_cmd=False)
http = AM7020HTTP(nb, HTTP_SERVER)
```
Initialize nb and connect to NBIOT base station:
```Python
while((not nb.init() or (not nb.nbiotConnect(apn, band)))):
print(".")
while(not nb.waitForNetwork()):
print(".")
sleep(5)
```
HTTP GET and POST:
```Python
http.get(HTTP_GET_API)
state_code = http.responseStatusCode()
body = http.responseBody()
http.post(HTTP_POST_API, content_type="application/json", body="{\"value\": \"POST\"}")
state_code = http.responseStatusCode()
body = http.responseBody()
```