微信小程序调试完成
This commit is contained in:
parent
6b3dd07883
commit
43543bec12
File diff suppressed because one or more lines are too long
@ -103,7 +103,7 @@
|
||||
<bEvRecOn>1</bEvRecOn>
|
||||
<bSchkAxf>0</bSchkAxf>
|
||||
<bTchkAxf>0</bTchkAxf>
|
||||
<nTsel>4</nTsel>
|
||||
<nTsel>6</nTsel>
|
||||
<sDll></sDll>
|
||||
<sDllPa></sDllPa>
|
||||
<sDlgDll></sDlgDll>
|
||||
@ -114,7 +114,7 @@
|
||||
<tDlgDll></tDlgDll>
|
||||
<tDlgPa></tDlgPa>
|
||||
<tIfile></tIfile>
|
||||
<pMon>Segger\JL2CM3.dll</pMon>
|
||||
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
|
@ -824,7 +824,7 @@
|
||||
:10336000C4E9008721464A46A1F13400FFF7EEFB8D
|
||||
:10337000A4F13400BDE8F84340F26A51FFF7D4BB32
|
||||
:10338000F805002008F05ABC08F094BCFEE770472E
|
||||
:1033900004A0FDF787F8FFF7F7FF012008F04CF9CC
|
||||
:10339000FFF7FAFF03A0FDF785F8012008F04CF9CC
|
||||
:1033A000FBE7000077656C636F6D6520746F2074B8
|
||||
:1033B000686520546F75636847465820776F726C54
|
||||
:1033C0006400000010B5502080F31188BFF34F8FC8
|
||||
|
@ -563,8 +563,8 @@ static void MX_GPIO_Init(void)
|
||||
void StartDefaultTask(void const * argument)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
printf("welcome to the TouchGFX world");
|
||||
MX_TouchGFX_Process();
|
||||
printf("welcome to the TouchGFX world");
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <sht3x.h>
|
||||
|
||||
#define LOG_TAG "sht30"
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
#define LOG_LVL LOG_LVL_INFO
|
||||
#include <ulog.h>
|
||||
#define THREAD_PRIORITY 9
|
||||
#define THREAD_STACK_SIZE 1024
|
||||
|
@ -560,7 +560,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>TouchGFX_app</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@ -912,7 +912,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>TouchGFX_gui</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
|
@ -188,8 +188,8 @@
|
||||
#define AT_DEVICE_USING_ESP8266
|
||||
#define AT_DEVICE_ESP8266_INIT_ASYN
|
||||
#define AT_DEVICE_ESP8266_SAMPLE
|
||||
#define ESP8266_SAMPLE_WIFI_SSID "xgld1"
|
||||
#define ESP8266_SAMPLE_WIFI_PASSWORD "xgld64627816"
|
||||
#define ESP8266_SAMPLE_WIFI_SSID "ChinaNet-ssssss"
|
||||
#define ESP8266_SAMPLE_WIFI_PASSWORD "SQHWLK9394"
|
||||
#define ESP8266_SAMPLE_CLIENT_NAME "uart3"
|
||||
#define ESP8266_SAMPLE_RECV_BUFF_LEN 512
|
||||
#define PKG_USING_AT_DEVICE_LATEST_VERSION
|
||||
|
@ -8,8 +8,8 @@ App({
|
||||
wx.setStorageSync('logs', logs)
|
||||
},
|
||||
globalData: {
|
||||
productKey: "a1zHu27ouVy",
|
||||
deviceName: "helloMultiMeter",
|
||||
deviceSecret: "Zvk2aozVzoZx0vISPRp87vgAPV9g1RFm"
|
||||
ProductKey: "",
|
||||
DeviceName: "",
|
||||
DeviceSecret: ""
|
||||
},
|
||||
})
|
BIN
demo/4_微信小程序/不使用云服务/wechat_ali_esp8266/image/scan.png
Normal file
BIN
demo/4_微信小程序/不使用云服务/wechat_ali_esp8266/image/scan.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 280 B |
@ -1,23 +1,27 @@
|
||||
// pages/device/device.js
|
||||
var mqtt = require('../../utils/mqtt.min.js')
|
||||
const crypto = require('../../utils/hex_hmac_sha1.js');
|
||||
var app = getApp();
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
client: null,
|
||||
deviceData: {},
|
||||
detail: {
|
||||
id: "",
|
||||
name: "",
|
||||
status:"",
|
||||
deviceData: {
|
||||
name : "",
|
||||
temperature: "",
|
||||
humidity: "",
|
||||
airquality: ""
|
||||
},
|
||||
modelData: {
|
||||
},
|
||||
items: [
|
||||
{ name: '红色', value: 0, color: "red" },
|
||||
{ name: '绿色', value: 1, color: "green" },
|
||||
{ name: '蓝色', value: 2, color: "blue" },
|
||||
]
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@ -30,9 +34,137 @@ Page({
|
||||
detail: options,
|
||||
}
|
||||
)
|
||||
|
||||
that.doConnect()
|
||||
},
|
||||
queryDeviceData(res) {
|
||||
var that = this;
|
||||
console.log('订阅成功!');
|
||||
},
|
||||
controlDeviceData:function(e){
|
||||
console.log('提交的数据信息:',e.detail.value)
|
||||
this.setData({
|
||||
modelData: {
|
||||
"method": "thing.event.property.post",
|
||||
"id": "12345",
|
||||
"params": {
|
||||
"color": e.detail.value.color,
|
||||
"airconditioners":e.detail.value.airconditioners_switch,
|
||||
"windows":e.detail.value.windows_switch,
|
||||
"temperatyre_threshold":e.detail.value.temperatyre_threshold,
|
||||
"humidity_threshold":e.detail.value.humidity_threshold
|
||||
},
|
||||
"version": "1.0"
|
||||
},
|
||||
})
|
||||
if (this.data.client && this.data.client.connected) {
|
||||
this.data.client.publish('/'+app.globalData.ProductKey+'/'+app.globalData.DeviceName+'/user/update', JSON.stringify(this.data.modelData));
|
||||
wx.showToast({
|
||||
title: '发送成功'
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '请先连接服务器',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
},
|
||||
doConnect(){
|
||||
var that = this;
|
||||
const deviceConfig = {
|
||||
productKey: app.globalData.ProductKey,
|
||||
deviceName: app.globalData.DeviceName,
|
||||
deviceSecret: app.globalData.DeviceSecret,
|
||||
regionId: "cn-shanghai"
|
||||
};
|
||||
const options = that.initMqttOptions(deviceConfig);
|
||||
console.log(options)
|
||||
//替换productKey为你自己的产品的
|
||||
that.data.client = mqtt.connect('wxs://'+app.globalData.ProductKey+'.iot-as-mqtt.cn-shanghai.aliyuncs.com',options)
|
||||
that.data.client.on('connect', function () {
|
||||
console.log('连接服务器成功')
|
||||
//订阅主题,替换productKey和deviceName(这里的主题可能会不一样,具体请查看后台设备Topic列表或使用自定义主题)
|
||||
that.data.client.subscribe('/'+app.globalData.ProductKey+'/'+app.globalData.DeviceName+'/user/get', function (err) {
|
||||
if (!err) {
|
||||
console.log('订阅成功!');
|
||||
wx.showToast({
|
||||
title: "链接成功",
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
//接收消息监听
|
||||
that.data.client.on('message', function (topic, message) {
|
||||
// message is Buffer
|
||||
console.log('收到消息:'+message.toString())
|
||||
var devicejsonData = message.toString()
|
||||
var devicejsonData = JSON.parse(devicejsonData)
|
||||
that.setData({
|
||||
deviceData: {
|
||||
name : devicejsonData.deviceName,
|
||||
temperature: devicejsonData.Temperature.toFixed(1).toString(),
|
||||
humidity: devicejsonData.Humidity.toFixed(1).toString(),
|
||||
airquality: "良好"
|
||||
},
|
||||
})
|
||||
//关闭连接 client.end()
|
||||
})
|
||||
//服务器连接异常的回调
|
||||
that.data.client.on("error", function(error) {
|
||||
console.log(" 服务器 error 的回调" + error)
|
||||
|
||||
})
|
||||
//服务器重连连接异常的回调
|
||||
that.data.client.on("reconnect", function() {
|
||||
console.log(" 服务器 reconnect的回调")
|
||||
})
|
||||
//服务器连接异常的回调
|
||||
that.data.client.on("offline", function(errr) {
|
||||
console.log(" 服务器offline的回调")
|
||||
})
|
||||
},
|
||||
|
||||
//IoT平台mqtt连接参数初始化
|
||||
initMqttOptions(deviceConfig) {
|
||||
|
||||
const params = {
|
||||
productKey: deviceConfig.productKey,
|
||||
deviceName: deviceConfig.deviceName,
|
||||
timestamp: Date.now(),
|
||||
clientId: Math.random().toString(36).substr(2),
|
||||
}
|
||||
//CONNECT参数
|
||||
const options = {
|
||||
keepalive: 60, //60s
|
||||
clean: true, //cleanSession不保持持久会话
|
||||
protocolVersion: 4 //MQTT v3.1.1
|
||||
}
|
||||
//1.生成clientId,username,password
|
||||
options.password = this.signHmacSha1(params, deviceConfig.deviceSecret);
|
||||
options.clientId = `${params.clientId}|securemode=2,signmethod=hmacsha1,timestamp=${params.timestamp}|`;
|
||||
options.username = `${params.deviceName}&${params.productKey}`;
|
||||
|
||||
return options;
|
||||
},
|
||||
|
||||
/*
|
||||
生成基于HmacSha1的password
|
||||
参考文档:https://help.aliyun.com/document_detail/73742.html?#h2-url-1
|
||||
*/
|
||||
signHmacSha1(params, deviceSecret) {
|
||||
|
||||
let keys = Object.keys(params).sort();
|
||||
// 按字典序排序
|
||||
keys = keys.sort();
|
||||
const list = [];
|
||||
keys.map((key) => {
|
||||
list.push(`${key}${params[key]}`);
|
||||
});
|
||||
const contentStr = list.join('');
|
||||
return crypto.hex_hmac_sha1(deviceSecret, contentStr);
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
|
@ -4,21 +4,21 @@
|
||||
设备信息
|
||||
</view>
|
||||
<view class="box">
|
||||
<view class="cell">
|
||||
<view class="status-left">设备ID</view>
|
||||
<view class="status-right">{{detail.id}}</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view class="status-left">设备名称</view>
|
||||
<view class="status-right">{{detail.name}}</view>
|
||||
<view class="status-right">{{deviceData.name}}</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view class="status-left">环境湿度</view>
|
||||
<view class="status-right">{{detail.status}}%</view>
|
||||
<view class="status-right">{{deviceData.humidity}}%</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view class="status-left">环境温度</view>
|
||||
<view class="status-right">{{deviceData.temperature}}℃</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view class="status-left">空气质量</view>
|
||||
<view class="status-right">{{deviceData.airquality}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -36,13 +36,27 @@
|
||||
</view>
|
||||
<view class="box">
|
||||
<view class="cell">
|
||||
<view>开关</view>
|
||||
<view>空调</view>
|
||||
<view>
|
||||
<switch name="power_switch" checked="{{deviceData.power_switch}}" />
|
||||
<switch name="airconditioners_switch" checked="{{deviceData.airconditioners_switch}}" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view>窗户</view>
|
||||
<view>
|
||||
<switch name="windows_switch" checked="{{deviceData.windows_switch}}" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view>闹钟</view>
|
||||
<view class="weui-cell__bd">
|
||||
<picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
|
||||
<view class="weui-input">{{time}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view>颜色</view>
|
||||
<view>氛围灯</view>
|
||||
<view>
|
||||
<radio-group name="color">
|
||||
<label style="color:{{item.color}}" class="radio" wx:for="{{items}}" wx:key="unique" wx:for-index="idx">
|
||||
@ -52,9 +66,15 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view>亮度</view>
|
||||
<view style="width:80%">
|
||||
<slider name="brightness" min="0" max="100" value="{{deviceData.brightness.Value}}" show-value/>
|
||||
<view>温度阈值</view>
|
||||
<view style="width:70%">
|
||||
<slider name="temperatyre_threshold" min="0" max="100" value="{{deviceData.temperatyre.Value}}" show-value/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view>湿度阈值</view>
|
||||
<view style="width:70%">
|
||||
<slider name="humidity_threshold" min="0" max="100" value="{{deviceData.humidity.Value}}" show-value/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -1,6 +1,5 @@
|
||||
// pages/home/home.js
|
||||
var mqtt = require('../../utils/mqtt.min.js')
|
||||
const crypto = require('../../utils/hex_hmac_sha1.js');
|
||||
|
||||
var app = getApp();
|
||||
Page({
|
||||
|
||||
@ -8,7 +7,11 @@ Page({
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
devices: [],
|
||||
device: {
|
||||
ProductKey: "",
|
||||
DeviceName: "",
|
||||
DeviceSecret: ""
|
||||
},
|
||||
imgUrls: [
|
||||
'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
|
||||
'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',
|
||||
@ -36,87 +39,32 @@ Page({
|
||||
})
|
||||
},
|
||||
formSubmit:function(e){
|
||||
console.log('提交的数据信息:',e.detail.value)
|
||||
console.log(e.detail.value)
|
||||
app.globalData = e.detail.value;
|
||||
wx.navigateTo({
|
||||
url: '/pages/device/device'
|
||||
})
|
||||
},
|
||||
formReset: function () {
|
||||
console.log('表单重置了')
|
||||
|
||||
scanBack(res) {
|
||||
var that = this;
|
||||
// 允许从相机和相册扫码
|
||||
wx.scanCode({
|
||||
success (res) {
|
||||
app.globalData = JSON.parse(res.result);
|
||||
that.setData({
|
||||
device: {
|
||||
ProductKey : app.globalData.ProductKey,
|
||||
DeviceName: app.globalData.DeviceName,
|
||||
DeviceSecret: app.globalData.DeviceSecret,
|
||||
},
|
||||
})
|
||||
|
||||
console.log(that.data.device)
|
||||
}
|
||||
})
|
||||
},
|
||||
doConnect(){
|
||||
var that = this;
|
||||
const deviceConfig = {
|
||||
productKey: "a1zHu27ouVy",
|
||||
deviceName: "helloMultiMeter",
|
||||
deviceSecret: "Zvk2aozVzoZx0vISPRp87vgAPV9g1RFm",
|
||||
regionId: "cn-shanghai"
|
||||
};
|
||||
const options = that.initMqttOptions(deviceConfig);
|
||||
console.log(options)
|
||||
//替换productKey为你自己的产品的
|
||||
const client = mqtt.connect('wxs://a1zHu27ouVy.iot-as-mqtt.cn-shanghai.aliyuncs.com',options)
|
||||
client.on('connect', function () {
|
||||
console.log('连接服务器成功')
|
||||
wx.showToast({
|
||||
title: '连接成功'
|
||||
})
|
||||
|
||||
//订阅主题,替换productKey和deviceName(这里的主题可能会不一样,具体请查看后台设备Topic列表或使用自定义主题)
|
||||
client.subscribe('/a1zHu27ouVy/helloMultiMeter/user/data', function (err) {
|
||||
if (!err) {
|
||||
console.log('订阅成功!');
|
||||
}
|
||||
})
|
||||
})
|
||||
//接收消息监听
|
||||
client.on('message', function (topic, message) {
|
||||
// message is Buffer
|
||||
console.log('收到消息:'+message.toString())
|
||||
//关闭连接 client.end()
|
||||
})
|
||||
},
|
||||
//IoT平台mqtt连接参数初始化
|
||||
initMqttOptions(deviceConfig) {
|
||||
|
||||
const params = {
|
||||
productKey: deviceConfig.productKey,
|
||||
deviceName: deviceConfig.deviceName,
|
||||
timestamp: Date.now(),
|
||||
clientId: Math.random().toString(36).substr(2),
|
||||
}
|
||||
//CONNECT参数
|
||||
const options = {
|
||||
keepalive: 60, //60s
|
||||
clean: true, //cleanSession不保持持久会话
|
||||
protocolVersion: 4 //MQTT v3.1.1
|
||||
}
|
||||
//1.生成clientId,username,password
|
||||
options.password = this.signHmacSha1(params, deviceConfig.deviceSecret);
|
||||
options.clientId = `${params.clientId}|securemode=2,signmethod=hmacsha1,timestamp=${params.timestamp}|`;
|
||||
options.username = `${params.deviceName}&${params.productKey}`;
|
||||
|
||||
return options;
|
||||
},
|
||||
|
||||
/*
|
||||
生成基于HmacSha1的password
|
||||
参考文档:https://help.aliyun.com/document_detail/73742.html?#h2-url-1
|
||||
*/
|
||||
signHmacSha1(params, deviceSecret) {
|
||||
|
||||
let keys = Object.keys(params).sort();
|
||||
// 按字典序排序
|
||||
keys = keys.sort();
|
||||
const list = [];
|
||||
keys.map((key) => {
|
||||
list.push(`${key}${params[key]}`);
|
||||
});
|
||||
const contentStr = list.join('');
|
||||
return crypto.hex_hmac_sha1(deviceSecret, contentStr);
|
||||
},
|
||||
bindGetUserInfo(res) {
|
||||
var that = this;
|
||||
that.doConnect()
|
||||
that.goToIndex()
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
|
@ -9,14 +9,44 @@
|
||||
</swiper>
|
||||
</view>
|
||||
</view>
|
||||
<form bindsubmit="formSubmit" bindrest="formReset">
|
||||
|
||||
<input type="ProductKey" name="ProductKey" placeholder="请输入ProductKey" />
|
||||
<input type="DeviceName" name="DeviceName" placeholder="请输入DeviceName" />
|
||||
<input type="DeviceSecret" name="DeviceSecret" placeholder="请输入DeviceSecret"/>
|
||||
<button form-type="submit">提交</button>
|
||||
<button form-type="reset">重置</button>
|
||||
<view class='setting' bindtap='scanBack'>
|
||||
<image class='btnImg' src='/image/scan.png'style="width:45rpx;height:45rpx;"></image>
|
||||
<text style="font-size:0.8rem;color:#808080">设备身份三元组:</text>
|
||||
</view>
|
||||
<form bindsubmit="formSubmit">
|
||||
<view class="weui-cells weui-cells_after-title">
|
||||
<view class="weui-cell hw__h3">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">ProductKey:</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input class="weui-input" name="ProductKey" placeholder="" value="{{device.ProductKey}}"/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-cells weui-cells_after-title">
|
||||
<view class="weui-cell hw__h3">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">DeviceName:</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input class="weui-input" name="DeviceName" placeholder="" value="{{device.DeviceName}}"/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-cells weui-cells_after-title">
|
||||
<view class="weui-cell hw__h3">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">DeviceSecret:</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input class="weui-input" name="DeviceSecret" placeholder="" value="{{device.DeviceSecret}}"/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<button class="welcome-btn" form-type="submit">链接服务器</button>
|
||||
</form>
|
||||
<view>
|
||||
<button class="welcome-btn" bindtap="navigateTo">链接服务器</button>
|
||||
</view>
|
||||
|
||||
|
||||
|
||||
|
@ -78,6 +78,9 @@
|
||||
color: #FF1493;
|
||||
margin-right: 40rpx;
|
||||
}
|
||||
.hw__h3 {
|
||||
font-size: 14px;
|
||||
}
|
||||
.welcome-btn {
|
||||
background-color: #27e4b5;
|
||||
color: white;
|
||||
@ -92,4 +95,12 @@
|
||||
left: 20px;
|
||||
right:20px;
|
||||
z-index: 2;
|
||||
}
|
||||
}
|
||||
|
||||
.setting{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: left;
|
||||
justify-content: left;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
"ignore": []
|
||||
},
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"urlCheck": true,
|
||||
"es6": true,
|
||||
"enhance": true,
|
||||
"postcss": true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user