从0开始玩转Gokit3 SOC(3)温湿度远程监控应用-数值量上报
本帖最后由 bigfanofloT 于 2017-1-4 19:12 编辑本应用基于机智云Gokit3 SOC硬件平台,演示了如何通过通过板载DHT11温湿度传感器感知温湿度,然后上报到云端,从而可在手机APP端监控的应用。分为以下三步:1. 机智云开发者中心创建产品;2. 机智云开发者中心生成SOC方案工程;3. 移植温湿度传感器DHT11驱动,编写用户应用;视频:http://player.youku.com/player.php/sid/XMTkwMjEwNzIyNA==/v.swf首先在机智云开发者中心创建产品。
填写好产品信息后新建数据点,我们建立如下温、湿度数据点:然后我们在开发向导里面,生成soc工程:下载生成的工程,解压后,其目录如下:各个文件作用如下:生成的工程包含了基本的框架,需要用户自己添加驱动和应用逻辑,本例来说就是温湿度传感器DHT11的底层驱动和应用,生成的工程文件夹名太长,为了方便改为soc_esp8266_HumTemp。这里,我们从机智云官网下载Gokit3 SOC微信宠物屋源码,把里面的关于底板RGB5050 全彩LED的驱动文件hal_rgb_led.h和hal_rgb_led.c文件以及传感器DHT11的驱动文件hal_temp_hum.c和hal_temp_hum.h拷贝到我们的工程中来。下载源码:
http://dev.gizwits.com/zh-cn/developer/resource/hardware?type=GoKit解压后找到如下4个LED和温湿度传感器的驱动c和h文件:把它们拷贝到生成的工程里面对应位置:接下来就是修改生成的工程源码了,我这里使用Subelime Text文本编辑器修改;
找到..\app\user目录的主函数user_main.c文件,首先添加2个驱动头文件路劲:把传感器和RGB LED初始化函数放到voidICACHE_FLASH_ATTR user_init(void)里面:在按键回调函数里面添加如下代码,是为了适应测试APP的提示;在这里添加1个宏定义,用于控制定时采集温湿度;在如下函数里面添加用户代码:定时读取温湿度,然后上报到云端;工程修改完毕后,按照教程http://docs.gizwits.com/zh-cn/deviceDev/WiFiSOC/GoKit3S%E4%BA%8C%E6%AC%A1%E5%BC%80%E5%8F%91.html搭建开发环境、编译代码、烧录。工程源码下载:**** Hidden Message *****PDF教程:**** Hidden Message *****
过来看看,支持一下!!! bigfanofloT 发表于 2017-10-1 17:13
把你的发上来看看
这个就是系统自动生成的新代码,未按照该贴编辑前可以编译,按照该贴修改以后报错无法编译,谢谢。
/**
****************************************
* @file user_main.c
* @brief The program entry file
* @author Gizwits
* @date 2017-07-19
* @version V03030000
* @copyright Gizwits
*
* @note 机智云.只为智能硬件而生
* Gizwits Smart Cloudfor Smart Products
* 链接|增值ֵ|开放|中立|安全|自有|自由|生态
* www.gizwits.com
*
****************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "user_interface.h"
#include "gagent_soc.h"
#include "user_devicefind.h"
#include "user_webserver.h"
#include "gizwits_product.h"
#include "driver/hal_key.h"
#if ESP_PLATFORM
#include "user_esp_platform.h"
#endif
#ifdef SERVER_SSL_ENABLE
#include "ssl/cert.h"
#include "ssl/private_key.h"
#else
#ifdef CLIENT_SSL_ENABLE
unsigned char *default_certificate;
unsigned int default_certificate_len = 0;
unsigned char *default_private_key;
unsigned int default_private_key_len = 0;
#endif
#endif
/**@name User timers related parameters
* @{
*/
#define USER_TIME_MS 1000 ///< Timing time in milliseconds
LOCAL os_timer_t userTimer; ///< User timer structure
/**@} */
/**@name Key related definitions
* @{
*/
#define GPIO_KEY_NUM 2 ///< Defines the total number of key members
#define KEY_0_IO_MUX PERIPHS_IO_MUX_GPIO0_U ///< ESP8266 GPIO function
#define KEY_0_IO_NUM 0 ///< ESP8266 GPIO number
#define KEY_0_IO_FUNC FUNC_GPIO0 ///< ESP8266 GPIO name
#define KEY_1_IO_MUX PERIPHS_IO_MUX_MTMS_U ///< ESP8266 GPIO function
#define KEY_1_IO_NUM 14 ///< ESP8266 GPIO number
#define KEY_1_IO_FUNC FUNC_GPIO14 ///< ESP8266 GPIO name
LOCAL key_typedef_t * singleKey; ///< Defines a single key member array pointer
LOCAL keys_typedef_t keys; ///< Defines the overall key module structure pointer
/**@} */
/**
* Key1 key short press processing
* @param none
* @return none
*/
LOCAL void ICACHE_FLASH_ATTR key1ShortPress(void)
{
GIZWITS_LOG("#### KEY1 short press ,Production Mode\n");
gizwitsSetMode(WIFI_PRODUCTION_TEST);
}
/**
* Key1 key presses a long press
* @param none
* @return none
*/
LOCAL void ICACHE_FLASH_ATTR key1LongPress(void)
{
GIZWITS_LOG("#### key1 long press, default setup\n");
gizwitsSetMode(WIFI_RESET_MODE);
}
/**
* Key2 key to short press processing
* @param none
* @return none
*/
LOCAL void ICACHE_FLASH_ATTR key2ShortPress(void)
{
GIZWITS_LOG("#### key2 short press, soft ap mode \n");
gizwitsSetMode(WIFI_SOFTAP_MODE);
}
/**
* Key2 button long press
* @param none
* @return none
*/
LOCAL void ICACHE_FLASH_ATTR key2LongPress(void)
{
GIZWITS_LOG("#### key2 long press, airlink mode\n");
gizwitsSetMode(WIFI_AIRLINK_MODE);
}
/**
* Key to initialize
* @param none
* @return none
*/
LOCAL void ICACHE_FLASH_ATTR keyInit(void)
{
singleKey = keyInitOne(KEY_0_IO_NUM, KEY_0_IO_MUX, KEY_0_IO_FUNC,
key1LongPress, key1ShortPress);
singleKey = keyInitOne(KEY_1_IO_NUM, KEY_1_IO_MUX, KEY_1_IO_FUNC,
key2LongPress, key2ShortPress);
keys.singleKey = singleKey;
keyParaInit(&keys);
}
/**
* @brief user_rf_cal_sector_set
* Use the 636 sector (2544k ~ 2548k) in flash to store the RF_CAL parameter
* @param none
* @return none
*/
uint32_t ICACHE_FLASH_ATTR user_rf_cal_sector_set()
{
return 636;
}
/**
* @brief program entry function
* In the function to complete the user-related initialization
* @param none
* @return none
*/
void ICACHE_FLASH_ATTR user_init(void)
{
uint32_t system_free_size = 0;
wifi_station_set_auto_connect(1);
wifi_set_sleep_type(NONE_SLEEP_T);//set none sleep mode
espconn_tcp_set_max_con(10);
uart_init_3(9600,115200);
UART_SetPrintPort(1);
GIZWITS_LOG( "---------------SDK version:%s--------------\n", system_get_sdk_version());
GIZWITS_LOG( "system_get_free_heap_size=%d\n",system_get_free_heap_size());
struct rst_info *rtc_info = system_get_rst_info();
GIZWITS_LOG( "reset reason: %x\n", rtc_info->reason);
if (rtc_info->reason == REASON_WDT_RST ||
rtc_info->reason == REASON_EXCEPTION_RST ||
rtc_info->reason == REASON_SOFT_WDT_RST)
{
if (rtc_info->reason == REASON_EXCEPTION_RST)
{
GIZWITS_LOG("Fatal exception (%d):\n", rtc_info->exccause);
}
GIZWITS_LOG( "epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n",
rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc);
}
if (system_upgrade_userbin_check() == UPGRADE_FW_BIN1)
{
GIZWITS_LOG( "---UPGRADE_FW_BIN1---\n");
}
else if (system_upgrade_userbin_check() == UPGRADE_FW_BIN2)
{
GIZWITS_LOG( "---UPGRADE_FW_BIN2---\n");
}
keyInit();
userInit();
gizwitsInit();
//user timer
os_timer_disarm(&userTimer);
os_timer_setfn(&userTimer, (os_timer_func_t *)userHandle, NULL);
os_timer_arm(&userTimer, USER_TIME_MS, 1);
GIZWITS_LOG("--- system_free_size = %d ---\n", system_get_free_heap_size());
} bigfanofloT 发表于 2017-10-1 17:13
把你的发上来看看
gen_misc.sh version 20150511
boot mode: new
app:1
spi speed: 40 MHz
spi mode: QIO
spi_size_map:6
make: Entering directory '/home/cobetckoe/workspace/logive/app/user'
DEPEND: xtensa-lx106-elf-gcc -M -Os -g -Wpointer-arith -Wundef -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -I include -I ./ -I ../../include/ets -I ../include -I ../../include -I ../../include/eagle -I ../..//app/gagent/inc -I ../..//app/Gizwits -I ../..//app/Utils user_json.c
/bin/sh: 2: cannot create .output/eagle/debug/obj/user_json.d.26294: Permission denied
DEPEND: xtensa-lx106-elf-gcc -M -Os -g -Wpointer-arith -Wundef -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -I include -I ./ -I ../../include/ets -I ../include -I ../../include -I ../../include/eagle -I ../..//app/gagent/inc -I ../..//app/Gizwits -I ../..//app/Utils user_main.c
/bin/sh: 2: cannot create .output/eagle/debug/obj/user_main.d.26299: Permission denied
xtensa-lx106-elf-gcc -Os -g -Wpointer-arith -Wundef -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -I include -I ./ -I ../../include/ets -I ../include-I ../../include -I ../../include/eagle -I ../..//app/gagent/inc -I ../..//app/Gizwits -I ../..//app/Utils-o .output/eagle/debug/obj/user_main.o -c user_main.c
user_main.c: In function 'user_rf_cal_sector_set':
user_main.c:152:30: error: 'dataPoint_t' has no member named 'valuetemp'
currentDataPoint.valuetemp = curTemperature;
^
user_main.c:153:30: error: 'dataPoint_t' has no member named 'valuehum'
currentDataPoint.valuehum = curHumidity;
^
../../Makefile:321: recipe for target '.output/eagle/debug/obj/user_main.o' failed
make: ** [.output/eagle/debug/obj/user_main.o] Error 1
make: Leaving directory '/home/cobetckoe/workspace/logive/app/user'
../Makefile:307: recipe for target '.subdirs' failed
make: ** [.subdirs] Error 2
好文,支持下 :victory::handshake:call: 非常不错,收藏 谢谢分享 :):):):):):):):):):):):):):D:D:D:D,好赞!!! 好东西:lol 支持.......... 看看,谢谢分享 你好,为什么我烧录了之后重启ESP8266,串口显示乱码,有一句不是乱码的,显示是don't use rtc mem data nivYan 发表于 2017-1-6 11:37
你好,为什么我烧录了之后重启ESP8266,串口显示乱码,有一句不是乱码的,显示是don't use rtc mem data ...
你的是Gokit3 SOC吗 bigfanofloT 发表于 2017-1-6 13:28
你的是Gokit3 SOC吗
不是,我申请的板子还没有发过来。现在使用的是ESP8266-12F的电路,电路和Gokit3 中ESP8266转接板原理图电路一样的,烧录乐鑫原厂的程序可以正常使用,现在烧录官方微信宠物屋SOC那个程序显示乱码,有时是直接不断重启,请问要怎么解决呢? nivYan 发表于 2017-1-6 13:53
不是,我申请的板子还没有发过来。现在使用的是ESP8266-12F的电路,电路和Gokit3 中ESP8266转接板原理图 ...
官方微信宠物屋源码要自己加PK码 bigfanofloT 发表于 2017-1-6 13:57
官方微信宠物屋源码要自己加PK码
不是pk码的问题,原来是串口接错的问题~~~回去仔细看了功能板的原理图才发现你们用的是ESP8266的UART1_TX引脚作为电脑串口!! 就是功能板上的UART0_TX和UART0_RX接的是ESP8266的UART-TX,而不是UART0_RX、UART0_TX,这神标注啊~~好想和你们的工程师聊聊人生:Q:Q。。好吧,终于解决了,谢谢啊 谢谢分享,墙裂支持 来学习了,关于soc的实在是太少了 这个帖子不错,看了下,自己利用手头的资源做了个插座,还是很不错的。后面考虑能不能烧录到esp8285中,如果行的话,那就更好了。:) 初次造访 谢谢,想下来试试。