Skip to content

solution_sensorhub #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 103 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,103 @@
# solution-Sensorhub
海外 vSIM EVB 项目推广 example,硬件选型:EC200UEU + Sense HAT(B)
# 快速上手

## 硬件准备

Windows电脑一台,建议 `Win10` 系统。

一套[EC200U-EU Quecpython 标准开发板](https://python.quectel.com/doc/Getting_started/zh/evb/ec200x-evb.html)(含天线,Type-C数据线)

一张能够正常使用的SIM卡

## 环境搭建

- 下载并安装EC200EU系列模组驱动:[QuecPython_USB_Driver_Win10_ASR](https://images.quectel.com/python/2023/04/Quectel_Windows_USB_DriverA_Customer_V1.1.13.zip)。


- 下载并安装 [VSCode](https://code.visualstudio.com/)。
- 下载并解压 [QPYCom](https://images.quectel.com/python/2022/12/QPYcom_V3.6.0.zip) 工具到电脑的合适位置。
- 下载[固件包](../../solutions/SimpliKit/EC200UEUAAR05A01M08_TEST0222.zip )。
- 下载[实验源码](https://gitee.com/dustin-wei/solution-sensorhub)

## 硬件连接

按照下图硬件连接:

<img src="./media/EVB_link1.png" style="zoom: 25%;" /><img src="./media/EVB_link2.png" style="zoom: 20%;" />



1. 将天线连接至标识有 `LTE` 字样的天线连接座上。

2. 使用 Type-C 数据线连接开发板和电脑。

3. 在图示位置SIM1卡槽插入可用的 Nano SIM 卡



## 设备开发

- ### 开机

完成硬件连接工作后,当PWR,SCK1亮起或电脑设备管理器的端口列表出现包含Quectel USB字样的COM口,表示开机成功

<img src="./media/USB.png" />



- ### 烧录固件包

参考[此章节](https://python.quectel.com/doc/Application_guide/zh/dev-tools/QPYcom/qpycom-dw.html#下载固件),烧录[固件包](../../solutions/SimpliKit/EC200UEUAAR05A01M08_TEST0222.zip )至开发板。

- ### 脚本导入与运行

1.参考[此章节](https://python.quectel.com/doc/Getting_started/zh/first_python.html#PC与模组间的文件传输),将源码目录下的code文件夹中的所有文件按原目录结构导入到模组文件系统中,如下图所示

<img src="./media/Qpycom.png" />

2.参考[此章节](https://python.quectel.com/doc/Getting_started/zh/first_python.html#执行脚本文件),执行主程序文件_main.py

3.参考[此章节](https://python.quectel.com/doc/Getting_started/zh/first_python.html#停止程序运行),停止程序运行。

## 业务调试

### 程序启动

执行_main.py脚本后,程序开始运行,会打印拨号信息,包括拨号状态、IP地址、DNS服务器地址,设备号等

<img src="./media/drivers_data.png" />

### 🚩 **Warning**

未插入SIM卡时,SCK1灯不会亮起,并且无法打印设备信息,插入SIM卡并重启设备后即可正常运行。

<img src="./media/sim_erro.png" />

### 数据检测

开始运行后每1s会打印一次检测到的温度1,湿度,气压,温度2,颜色的三原色的数据,

<img src="./media/data.png" />

### 数据更新

当检测以上4种的任一数据产生大于1或者原色产生大于150的变化时就会尝试上传云端更新数据,当上传成功时返回“send ret:True”,并且会提示是哪些数据发生了变化,APP读取云端最新数据进行数据更新。

<img src="./media/data_up.png" />

<img src="./media/yun.png" />

如果数据没有大于1的变化就会只在pqcom中打印当前检测的数据,不会发起上传云端。

<img src="./media/data1.png" />

位置定位更新,当模组位移超过50米时,云端会刷新定位信息,app读取最新定位信息。

<img src="./media/gnss.png" />

主动刷新APP数据,通过点击APP右上角刷新按键,APP会向服务器发起主动读取数据的指令,用于主动更新面板数据

<img src="./media/APP.png" style="zoom: 67%;" />

温度,湿度,气压,颜色,Lbs数据被获取成功

<img src="./media/data_get.png" style="zoom: 100%;" />
22 changes: 22 additions & 0 deletions code/Qth/依赖quecpython module清单.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
| module | 描述|
| --- | --- |
|uzlib|zlib解压缩|
|utime|时间相关功能|
|uos|基本系统服务|
|ujson|JSON编码和解码|
|uhashlib|哈希算法|
|urandom|生成随机数|
|ubinascii|二进制与ASCLL转换|
|umqtt|MQTT客户端|
|_thread|多线程|
|net|网络相关功能|
|sim|SIM卡功能|
|misc.Power|关机以及软件重启功能|
|ql_fs|高级文件操作|
|fota|fota升级|
|app_fota_download|py脚本升级|
|log|日志输出|
|modem|设备相关|
|queue|消息队列|
|request|http客户端|

30 changes: 8 additions & 22 deletions code/_main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import net
import utime
import checkNet
import dataCall
from misc import Power
from usr.libs import Application
from usr.libs.logging import getLogger
from usr.extensions import (
Expand All @@ -16,23 +13,6 @@
logger = getLogger(__name__)


def wait_network_ready():
for _ in range(3):
logger.info("wait network ready...")
code = checkNet.waitNetworkReady(300)
if code == (3, 1):
logger.info("network has been ready.")
break
else:
logger.warn("network not ready, code: {}".format(code))
net.setModemFun(0, 0)
utime.sleep_ms(200)
net.setModemFun(1, 0)
else:
logger.warn("power restart")
Power.powerRestart()


def create_app(name="SimpliKit", version="1.0.0", config_path="/usr/config.json"):
_app = Application(name, version)
_app.config.init(config_path)
Expand All @@ -46,9 +26,15 @@ def create_app(name="SimpliKit", version="1.0.0", config_path="/usr/config.json"


if __name__ == "__main__":
wait_network_ready()
while True:
lte = dataCall.getInfo(1, 0)
if lte[2][0] == 1:
logger.debug('lte network normal')
break
logger.debug('wait lte network normal...')
utime.sleep(3)

dataCall.setPDPContext(1, 0, 'BICSAPN', '', '', 0) #激活之前,应该先配置APN,这里配置第1路的APN
dataCall.setPDPContext(1, 0, 'BICSAPN', '', '', 0) # 激活之前,应该先配置APN,这里配置第1路的APN
dataCall.activate(1)

app = create_app()
Expand Down
3 changes: 2 additions & 1 deletion code/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"QTH_PRODUCT_KEY": "pe16Db",
"QTH_PRODUCT_SECRET": "ZGZMQWQ3QkVyN2Jm"
"QTH_PRODUCT_SECRET": "ZGZMQWQ3QkVyN2Jm",
"QTH_SERVER": "mqtt://iot-south.acceleronix.io:1883"
}
5 changes: 5 additions & 0 deletions code/config2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"QTH_PRODUCT_KEY": "pe17gQ",
"QTH_PRODUCT_SECRET": "REdmNmlMRS8yUmNi",
"QTH_SERVER": "mqtt://iot-south.quectelcn.com:1883"
}
5 changes: 5 additions & 0 deletions code/extensions/gnss_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from usr.libs import CurrentApp
from usr.libs.threading import Thread
from usr.libs.logging import getLogger
import _thread
from .import qth_client
try:
from math import sin, asin, cos, radians, fabs, sqrt
except:
Expand Down Expand Up @@ -188,6 +190,7 @@ def start_update(self):
lng = lng_high + lng_low
if nmea_tuple[5] == "W":
lng = -lng

break

if nmea_data is not None:
Expand Down Expand Up @@ -218,3 +221,5 @@ def start_update(self):
else:
logger.error("send gnss to qth server fail")
utime.sleep(3)


24 changes: 23 additions & 1 deletion code/extensions/lbs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from usr.libs import CurrentApp
from usr.libs.threading import Thread
from usr.libs.logging import getLogger

import _thread

logger = getLogger(__name__)

Expand Down Expand Up @@ -57,3 +57,25 @@ def start_update(self):

logger.debug("send lbs data to qth server success, next report will be after 1800 seconds")
utime.sleep(1800)

def put_lbs(self):
while True:
lbs_data = self.read()
if lbs_data is None:
utime.sleep(2)
continue

for _ in range(3):
with CurrentApp().qth_client:
if CurrentApp().qth_client.sendLbs(lbs_data):
break
else:
logger.debug("send lbs data to qth server fail, next report will be after 2 seconds")
utime.sleep(2)
continue

logger.debug("send LBS data to qth server success")
break



44 changes: 33 additions & 11 deletions code/extensions/qth_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from usr.libs.threading import Lock
from usr.libs.logging import getLogger
from usr import Qth


from usr.libs import CurrentApp
from . import lbs_service
logger = getLogger(__name__)


Expand All @@ -24,7 +24,7 @@ def init_app(self, app):
app.register("qth_client", self)
Qth.init()
Qth.setProductInfo(app.config["QTH_PRODUCT_KEY"], app.config["QTH_PRODUCT_SECRET"])
Qth.setServer('mqtt://iot-south.acceleronix.io:1883')
Qth.setServer(app.config["QTH_SERVER"])
Qth.setEventCb(
{
"devEvent": self.eventCallback,
Expand All @@ -47,7 +47,6 @@ def start(self):

def stop(self):
Qth.stop()

def sendTsl(self, mode, value):
return Qth.sendTsl(mode, value)

Expand Down Expand Up @@ -76,15 +75,38 @@ def recvTslCallback(self, value):
def readTslCallback(self, ids, pkgId):
logger.info("readTsl ids:{} pkgId:{}".format(ids, pkgId))
value=dict()

temp1, humi =CurrentApp().sensor_service.get_temp1_and_humi()
press, temp2 = CurrentApp().sensor_service.get_press_and_temp2()
r,g,b = CurrentApp().sensor_service.get_rgb888()

value={
3:temp1,
4:humi,
5:temp2,
6:press,
7:{1:r, 2:g, 3:b},

}
lbs=lbs_service.LbsService()
lbs.put_lbs()



for id in ids:
if 1 == id:
value[1]=180.25
elif 2 == id:
value[2]=30
elif 3 == id:
value[3]=True
if 3 == id:
value[3]=temp1
elif 4 == id:
value[4]=humi
elif 5 == id:
value[5]=temp2
elif 6 == id:
value[6]=press
elif 7 == id:
value[7]={1:r, 2:g, 3:b}
Qth.ackTsl(1, value, pkgId)



def recvTslServerCallback(self, serverId, value, pkgId):
logger.info("recvTslServer serverId:{} value:{} pkgId:{}".format(serverId, value, pkgId))
Qth.ackTslServer(1, serverId, value, pkgId)
Expand Down
14 changes: 14 additions & 0 deletions code/extensions/sensor_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ def load(self):
Thread(target=self.start_update).start()


def get_temp1_and_humi(self):
return self.shtc3.getTempAndHumi()

def get_press_and_temp2(self):
return self.lps22hb.getTempAndPressure()
def get_rgb888(self):
rgb888 = self.tcs34725.getRGBValue()
logger.debug("R: {}, G: {}, B: {}".format((rgb888 >> 16) & 0xFF, (rgb888 >> 8) & 0xFF, rgb888 & 0xFF))

r = (rgb888 >> 16) & 0xFF
g = (rgb888 >> 8) & 0xFF
b = rgb888 & 0xFF
return r, g, b

def start_update(self):
prev_temp1 = None
prev_humi = None
Expand Down
Binary file added media/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/EVB_link1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/EVB_link2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/Qpycom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/USB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/app_ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/data1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/data_get.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/data_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/drivers_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/gnss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/service_model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/sim_erro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/software1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/software2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/yun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy