基于机智云gokit+Cat.1 4G模组转接板ML302-GC211的4G开发指南
手把手教你使用GoKit和GC211(4G模块)来实现4G网络的开发。包括模组接入、设备控制、数据采集,云端部署,APP开发等方面内容。难度较低,适合新手入门。教程内容:1. 将gokit2和gokit3实现4G网络模块GC211的接入2. STM32作为主控实现GOKIT全功能控制和采集3. arduino作为主控实现GOKIT全功能控制和采集4. 新版本APP快速开发5. 网页控制GOKIT开发板
材料准备:1,Gokit2 或 GoKit3一块
2,GC211 一块(基于ML103的4G模组)
3,杜邦线若干4,电脑一台5,机智云开发平台账号(点击注册)
https://club.gizwits.com/data/attachment/forum/202103/25/152532f6s3icy6inni0yzz.jpg.thumb.jpg
可根据自己需求选择对应的功能板和底板,其中gokit3支持SOC模式。
板子电路连接: 参考下图(如图看不清,参考附件中的原图):https://club.gizwits.com/data/attachment/forum/202103/24/153403ynjs6srw2rnrlz60.jpg.thumb.jpg
云端部署
1.进入新版本开发者中心https://developer.gizwits.com/menu/dashboard,点击左上角创建,选择园艺农林,养殖监控(如果是wifi模式,请选择其他,微信宠物屋gokit,gokit3)。
https://club.gizwits.com/data/attachment/forum/202103/24/153507kpgaagl2fkebnskl.jpg.thumb.jpg
2.如图创建一个产品,产品名称可以根据自己定义https://club.gizwits.com/data/attachment/forum/202103/24/153529i922i80rij2il988.jpg.thumb.jpg
3.将附件中的《数据点.xlsx》文件中的数据点导入产品之中。如果右上角没有管理按钮,那么先随便创建一个数据点之后就有了,之后就可以管理→导入模板https://club.gizwits.com/data/attachment/forum/202103/24/153554h4jznr8878n7r7hn.jpg.thumb.jpg
4.在MCU开发菜单分别生成Arduino代码和STM32代码并进行下载。可按照个人需求和手里面的开发板选择要生成的代码,此处我生成2种代码。
https://club.gizwits.com/data/attachment/forum/202103/24/153616ugm8ouqg4iamaiza.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/153628du6ieimee6c2ksui.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/153640ig9zqe55eogg58l8.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/153654sbev2yvggvvsvcve.jpg.thumb.jpg
STM32代码移植编写1.下载STM32驱动文件,机智云下载中心下载http://goms-1251025085.cosgz.myq ... 8-1513076127294.rar(也可以在附件中获取)
https://club.gizwits.com/data/attachment/forum/202103/24/153747z8l8llrt5tvud5q3.jpg.thumb.jpg
2.复制STM32驱动文件里面的STM32F103C8x.ioc到下载的代码文件中替换该文件。
https://club.gizwits.com/data/attachment/forum/202103/24/153812nl4cpzzyvjl9cs9y.jpg.thumb.jpg
3.复制驱动库代码_CubeMX版文件夹里面的驱动文件到下载代码的\Hal文件夹。
https://club.gizwits.com/data/attachment/forum/202103/24/153851cr9kzwzx64xv4pt2.jpg.thumb.jpg
4.打开下载代码里面的STM32F103C8x.ioc,需要在电脑上安装CUBEMX,安装方法自行百度。打开之后如下图所示。(此处个人提出建议,任何软件创建项目,不要包含中文路径,否则将会导致很多不可控问题,包括此软件。)
https://club.gizwits.com/data/attachment/forum/202103/24/153916jww13kplah1uo3zu.jpg.thumb.jpg
5.点击右上角generate code生成keil代码。https://club.gizwits.com/data/attachment/forum/202103/24/154058iappmao8iohh08cz.jpg.thumb.jpg
6.生成代码之后用keil打开代码,添加驱动文件到项目
https://club.gizwits.com/data/attachment/forum/202103/24/154129fneedlmddqglq9px.jpg.thumb.jpg
7.gizwits_product.c文件修改
添加相关的头文件
https://club.gizwits.com/data/attachment/forum/202103/24/154159bcp8fzzfdpc7yf3d.jpg.thumb.jpg
gizwitsEventProcess函数修改,包含各个传感器的驱动。对RGB LED开启红色的控制。 if(0x01 ==currentDataPoint.valueLED_OnOff) { ledRgbControl(254,0,0); } else { ledRgbControl(0,0,0); }
break;https://club.gizwits.com/data/attachment/forum/202103/24/154257dxm27z2mcpmmzpy8.jpg.thumb.jpg
其他颜色和电机的修改 case EVENT_LED_Color: currentDataPoint.valueLED_Color =dataPointPtr->valueLED_Color; GIZWITS_LOG("Evt: EVENT_LED_Color%d\n", currentDataPoint.valueLED_Color); switch(currentDataPoint.valueLED_Color) { case LED_Color_VALUE0: ledRgbControl(currentDataPoint.valueLED_R,currentDataPoint.valueLED_G,currentDataPoint.valueLED_B); break; case LED_Color_VALUE1: ledRgbControl(254, 254, 0); break; case LED_Color_VALUE2: ledRgbControl(254,0, 70); break; case LED_Color_VALUE3: ledRgbControl(238,30, 30); break; default: break; } break;
case EVENT_LED_R: currentDataPoint.valueLED_R =dataPointPtr->valueLED_R; GIZWITS_LOG("Evt:EVENT_LED_R%d\n",currentDataPoint.valueLED_R); ledRgbControl(currentDataPoint.valueLED_R,currentDataPoint.valueLED_G,currentDataPoint.valueLED_B); break; case EVENT_LED_G: currentDataPoint.valueLED_G =dataPointPtr->valueLED_G; GIZWITS_LOG("Evt:EVENT_LED_G%d\n",currentDataPoint.valueLED_G); ledRgbControl(currentDataPoint.valueLED_R,currentDataPoint.valueLED_G,currentDataPoint.valueLED_B); break; case EVENT_LED_B: currentDataPoint.valueLED_B =dataPointPtr->valueLED_B; GIZWITS_LOG("Evt:EVENT_LED_B%d\n",currentDataPoint.valueLED_B); ledRgbControl(currentDataPoint.valueLED_R,currentDataPoint.valueLED_G,currentDataPoint.valueLED_B); break; case EVENT_Motor_Speed: currentDataPoint.valueMotor_Speed =dataPointPtr->valueMotor_Speed; GIZWITS_LOG("Evt:EVENT_Motor_Speed%d\n",currentDataPoint.valueMotor_Speed); motorStatus(currentDataPoint.valueMotor_Speed); break;
https://club.gizwits.com/data/attachment/forum/202103/24/154507mq5s34rwd1ay5v88.jpg.thumb.jpg
如使用wifi方案,在WIFI_CON_ROUTER加上关灯操作。case WIFI_CON_ROUTER:
ledRgbControl(0, 250, 0);
https://club.gizwits.com/data/attachment/forum/202103/24/154538cx5oy9i9jx9yu1j1.jpg.thumb.jpg
userInit函数修改,增加各个驱动函数的初始化,数据点初始化memset((uint8_t*)¤tDataPoint, 0,sizeof(dataPoint_t)); delay_init(72); // 延时 初始化 rgbLedInit(); // RGB LED 初始化 dht11Init(); // 温湿度初始化 irInit(); // 红外初始化 motorInit(); // 电机初始化 motorStatus(0); // 电机转速初始化 /** Warning !!! DataPoint Variables Init ,Must Within The Data Range **/
currentDataPoint.valueLED_OnOff =0; currentDataPoint.valueInfrared =0; currentDataPoint.valueAlert_1 = 0; currentDataPoint.valueAlert_2 = 0; currentDataPoint.valueFault_LED =0; currentDataPoint.valueFault_Motor= 0; currentDataPoint.valueFault_TemHum= 0; currentDataPoint.valueFault_IR =0; currentDataPoint.valueLED_Color =0; currentDataPoint.valueLED_R = 0; currentDataPoint.valueLED_G = 0; currentDataPoint.valueLED_B = 0; currentDataPoint.valueMotor_Speed= 0; currentDataPoint.valueTemperature= 0; currentDataPoint.valueHumidity =0;
https://club.gizwits.com/data/attachment/forum/202103/24/154600cuuff06qqfsx0nhz.jpg.thumb.jpg
userHandle函数的修改,各个数据点的上传,传感器采集。 uint8_t ret = 0; static uint32_t thLastTimer = 0; ///< 新添加代码: 红外传感器数据获取 currentDataPoint.valueInfrared =irHandle(); ///< 新添加代码: 温湿度传感器数据获取 if((gizGetTimerCount()-thLastTimer) > 2000) //上报间隔2S { ret = dht11Read((uint8_t*)¤tDataPoint.valueTemperature,(uint8_t*)¤tDataPoint.valueHumidity); if(ret != 0) { GIZWITS_LOG("Failedtoread DHT11 [%d] \n", ret); } thLastTimer =gizGetTimerCount(); }
https://club.gizwits.com/data/attachment/forum/202103/24/154626dsn8er81e39nm8nx.jpg.thumb.jpg
8.将#include "main.h" 添加到hal下面的各个sensor驱动之中,否则sensor将会提示没有引脚定义报错。
https://club.gizwits.com/data/attachment/forum/202103/24/154658y75fp8x7ef8hehhn.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/154714cqik89li9599od2i.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/154737gaftdhk4413063fd.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/154749g2e51eejk08ii111.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/154805y2j0z8ggvvgxpdvc.jpg.thumb.jpg
9. main.c修改,增加头文件#include"hal_temp_hum.h"#include"hal_rgb_led.h"#include"hal_motor.h"#include"Hal_infrared.h"
#include"delay.h"https://club.gizwits.com/data/attachment/forum/202103/24/154855r7lkk7qmk86cgb9t.jpg.thumb.jpg
main.c 文件的 key2ShortPress( ) 函数与 key2LongPress( ) 函数中添加长/短按key2时的LED点亮代码。voidkey2ShortPress(void){GIZWITS_LOG("KEY2PRESS ,Soft APmode\n");#if!MODULE_TYPE gizwitsSetMode(WIFI_SOFTAP_MODE); #endif //Soft AP mode,RGB 红灯 ledRgbControl(250,0, 0);}voidkey2LongPress(void){ //AirLink mode GIZWITS_LOG("KEY2PRESS LONG,AirLink mode\n");#if!MODULE_TYPE gizwitsSetMode(WIFI_AIRLINK_MODE); #endif //AirLink mode,RGB 绿灯 ledRgbControl(0,250, 0);},
https://club.gizwits.com/data/attachment/forum/202103/24/154924niaa67z2xyl16ing.jpg.thumb.jpg
10.生成bin文件。魔术棒→user→$K\ARM\ARMCC\bin\fromelf.exe--bin --output=@L.bin !L
https://club.gizwits.com/data/attachment/forum/202103/24/154955xz4q454cg5445g5n.jpg.thumb.jpg
11.编译项目https://club.gizwits.com/data/attachment/forum/202103/24/155023u4ojpso4kp4yo3kr.jpg.thumb.jpg
12.STM32开发板集成串口下载,打开串口烧录软件mcuisp.exe,附件中可下载。
https://club.gizwits.com/data/attachment/forum/202103/24/155107cosenann7b2oa2so.jpg.thumb.jpg
选择开发板串口
https://club.gizwits.com/data/attachment/forum/202103/24/155138r61746gezlb7ceee.jpg.thumb.jpg
将如图所示开关拔到systemhttps://club.gizwits.com/data/attachment/forum/202103/24/155204atoubzmatealotkl.jpg.thumb.jpg
选择生成的固件文件https://club.gizwits.com/data/attachment/forum/202103/24/155225twjm0wxt0tgwwmh8.jpg.thumb.jpg
点击开始编程
https://club.gizwits.com/data/attachment/forum/202103/24/155305cn4659ug5il9bezq.jpg.thumb.jpg
烧录完成https://club.gizwits.com/data/attachment/forum/202103/24/155330oh5jf8hllgf5plfr.jpg.thumb.jpg
烧录完成之后将开关拔回flash,复位模组,就可以正常运行程序。
https://club.gizwits.com/data/attachment/forum/202103/24/155354jetx56xd6lmxd21m.jpg.thumb.jpg13.打开串口调试助手.exe,附件中可以下载。监听串口出现如下图所示日志代表程序烧录成功。https://club.gizwits.com/data/attachment/forum/202103/24/155421glllcrl8y1yuso4q.jpg.thumb.jpg
14.接上功能板和4G模组(插上普通4G卡)。云端设备上线。
https://club.gizwits.com/data/attachment/forum/202103/24/155447lfzwcne2z25117eu.jpg.thumb.jpg
15.打开机智云串口调试助手.exe,附件中或者官网下载中心可以下载。工具,二设备二维码,按照如图生成二维码。https://club.gizwits.com/data/attachment/forum/202103/24/155510x0y9hb0jjuvzq38z.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/155523ggkat6hkoqhkhz0n.jpg.thumb.jpg
16.使用机智云App扫码即可绑定设备,官网下载中心可以下载APP
https://club.gizwits.com/data/attachment/forum/202103/24/155545sshi9s8x8bg18x18.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/155605lp3nept8tll6bl6p.jpg.thumb.jpg
https://club.gizwits.com/data/attachment/forum/202103/24/155621ppndnp2didwhb7dn.jpg.thumb.jpg
到此STM32移植完成
Arduino代码移植编写
1.下载Arduino驱动文件,机智云下载中心下载http://goms-1251025085.cosgz.myq ... 6-1502093919120.zip(也可以在附件中获取)
https://club.gizwits.com/data/attachment/forum/202103/24/155647b1odo0t4jvwaojqo.jpg.thumb.jpg
2.将下载的驱动文件解压,将芯片驱动文件复制到安装好的arduino软件的..\libraries目录下。
https://club.gizwits.com/data/attachment/forum/202103/24/155710xbwel3ab83j98jab.jpg.thumb.jpg
将下载的代码进行解压,复制Gizwits到arduino 软件的.. \libraries目录下.https://club.gizwits.com/data/attachment/forum/202103/24/155742emoyco58s9eeq4ec.jpg.thumb.jpg
3. 使用arduino软件打开下载自动生成代码下载的文件中MCU_ArduinoUNOR3_source\examples\simpleTry\simpleTry.ino ,然后添加各驱动库的头文件,以及全局变量。#include<DHT.h>#include<ChainableLED.h>#include<MsTimer2.h>/***************************HAL define ***************************/#defineInfrared_PIN 2 ///< 红外IO管脚#define DHTPIN3 ///< 温湿度IO管脚#defineMOTOR_PINA 4 ///< 电机IO管脚#defineMOTOR_PINB 5 ///< 电机IO管脚#define KEY1 6///< 按键IO管脚#define KEY2 7///< 按键IO管脚//温湿度功能值定义#define DHTTYPEDHT11//电机功能值定义#defineMOTOR_MAX 100#defineMOTOR_MAX1 ‐100#defineMOTOR_MIN 0#defineMOTOR_16//按键功能值定义#defineKEY1_SHORT_PRESS 1#defineKEY1_LONG_PRESS 2#defineKEY2_SHORT_PRESS 4#defineKEY2_LONG_PRESS 8#define NO_KEY0#defineKEY_LONG_TIMER 3unsigned longLast_KeyTime = 0;uint8_tNetConfigureFlag = 0;uint8_tgaterSensorFlag = 0;typedef enum{LED_Costom =0x00,LED_Yellow =0x01,LED_Purple =0x02,LED_Pink =0x03,}LED_ColorTypeDef;DHTdht(DHTPIN, DHTTYPE);ChainableLEDleds(A5, A4, 1)
STM32代码移植的教程:https://mp.weixin.qq.com/s/Q-9wkRTlaQi_ra8HLsbS5g
下载代码以及相关文档:
链接:https://pan.baidu.com/s/17UMSLF3mqhy_V5VboIFDhw
提取码:z5ty
页:
[1]