代码如下

/***************************************************
这是一个例子的dfrobot维多-无线集成物联网建兴传感器和控制节点
*产品页面及更多信息:http://www.dfrobot.com.cn/goods-997.html
*特别设计的dfrobot维多产品的工作:
*
*图书馆叉从Adafruit
*
*劳伦写的
* BSD许可证,所有以上文字必须包含在任何重
*
****************************************************/ /*
This example code is used to connect the Yeelink cloud service (Official homepage: www.yeelink.net).
这个示例代码用于连接Yeelink云服务(官方主页:www.yeelink.net)。
The device required is just:
需要的设备是:
1. LM35 low cost temperature sensor or any device you used to upload data
1。LM35低成本温度传感器或任何用于上传数据的设备
2. And Wido
2。和Wido
注意:请不要忘记在使用前更改下面的设置!
1。wlan_ssid和wlan_pass
2。api_key
三.设备ID和传感器ID */ #include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#define Wido_IRQ 7
#define Wido_VBAT 5
#define Wido_CS 10 Adafruit_CC3000 Wido = Adafruit_CC3000(Wido_CS, Wido_IRQ, Wido_VBAT,
SPI_CLOCK_DIVIDER); // 你可以改变这个时钟速度。
//安全可以wlan_sec_unsec,wlan_sec_wep,wlan_sec_wpa或wlan_sec_wpa2
#define WLAN_SECURITY WLAN_SEC_WPA2 #define WLAN_SSID "modou-2002" // 不能超过32个字符!
#define WLAN_PASS "23456789" //用于连接的路由器或AP,不要忘记设置SSID和密码!! #define TCP_TIMEOUT 3000
//#define CC3000_TINY_DRIVER #define WEBSITE "api.yeelink.net"
#define API_key "733115abefe88b0033c035ac9e000000" // Update Your API Key. To get your API Key, please check the link below
// http://www.yeelink.net/user/user_profile void setup(){ Serial.begin();
Serial.println(F("Hello, CC3000!\n")); /* Initialise the module */
Serial.println(F("\nInitialising the CC3000 ..."));//初始化的CC3000…
if (!Wido.begin())
{
Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));//无法初始化的CC3000!检查你的线路?”
while();
} /* 尝试连接到接入点*/
char *ssid = WLAN_SSID; /* Max 32 chars */
Serial.print(F("\nAttempting to connect to "));
Serial.println(ssid); /* 注意:安全连接在“微”模式下不可用!
默认情况下connecttoap将重试下去,但是你可以通过
最大重试次数可选(大于零)作为第四个参数。
*/
if (!Wido.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while();
} Serial.println(F("Connected!")); /* 等待DHCP完成 */
Serial.println(F("Request DHCP"));
while (!Wido.checkDHCP())
{
delay(); // ToDo: 插入DHCP超时!
} } uint32_t ip = ;
float temp = ; void loop(){ static Adafruit_CC3000_Client WidoClient;
static unsigned long RetryMillis = ;
static unsigned long uploadtStamp = ;
static unsigned long sensortStamp = ; if(!WidoClient.connected() && millis() - RetryMillis > TCP_TIMEOUT){
// Update the time stamp更新时间戳
RetryMillis = millis(); Serial.println(F("Try to connect the cloud server"));
WidoClient.close(); // Get Yeelink IP address把Yeelink IP的地址
Serial.print(F("api.yeelink.net -> "));
while (ip == ) {
if (!Wido.getHostByName(WEBSITE, &ip)) { // Get the server IP address based on the domain name根据域名获取服务器IP地址
Serial.println(F("Couldn't resolve!"));
}
delay();
}
Wido.printIPdotsRev(ip);
Serial.println(F("")); // Connect to the Yeelink Server连接到服务器的yeelink
WidoClient = Wido.connectTCP(ip, ); // Try to connect cloud server
} if(WidoClient.connected() && millis() - uploadtStamp > ){
uploadtStamp = millis();
// If the device is connected to the cloud server, upload the data every 2000ms.如果设备连接到云服务器,上传数据的每一2000ms。 // Prepare Http Package for Yeelink & get length准备和包装长度yeelink for HTTP get
int length = ;
char lengthstr[]; // Create Http data package
char httpPackage[] = ""; strcat(httpPackage,"{\"value\":");
itoa(temp,httpPackage+strlen(httpPackage),); // push the data(temp) to the http data package日期(时间)Push the to the HTTP数据包
strcat(httpPackage,"}"); length = strlen(httpPackage); // get the length of data package获取数据包的长度
itoa(length,lengthstr,); // convert int to char array for posting
Serial.print(F("Length = "));
Serial.println(length); Serial.println(F("Connected to Yeelink server."));//yeelink服务器连接 // Send headers
Serial.print(F("Sending headers")); WidoClient.fastrprint(F("POST /v1.0/device/"));
WidoClient.fastrprint(F("100/sensor/20/datapoints")); //Please change your device ID and sensor ID here, after creating
//Please check the link: http://www.yeelink.net/user/devices
/*请在创建后更改您的设备ID和传感器id
/ /请查看链接:http://www.yeelink.net/user/devices
//例网址:*/
//The example URL: http://api.yeelink.net/v1.0/device/100/sensor/20/datapoints
WidoClient.fastrprintln(F(" HTTP/1.1"));
Serial.print(F(".")); WidoClient.fastrprintln(F("Host: api.yeelink.net"));
Serial.print(F(".")); WidoClient.fastrprint(F("U-ApiKey: "));
WidoClient.fastrprintln(API_key);
Serial.print(F(".")); WidoClient.fastrprint("Content-Length: ");
WidoClient.fastrprintln(lengthstr);
WidoClient.fastrprintln("");
Serial.print(F(".")); Serial.println(F(" done.")); // Send data
Serial.print(F("Sending data"));
WidoClient.fastrprintln(httpPackage); Serial.println(F(" done.")); /********** Get the http page feedback ***********/ unsigned long rTimer = millis();
Serial.println(F("Reading Cloud Response!!!\r\n"));
while (millis() - rTimer < ) {
while (WidoClient.connected() && WidoClient.available()) {
char c = WidoClient.read();
Serial.print(c);
}
}
delay(); // Wait for 1s to finish posting the data stream
WidoClient.close(); // Close the service connection RetryMillis = millis(); // Reset the timer stamp for applying the connection with the service
} if(millis() - sensortStamp > ){
sensortStamp = millis();
// 读LM35温度传感器值转换为度每隔1000ms。 int reading = analogRead();
temp = reading *0.0048828125*;
Serial.print(F("Real Time Temp: "));
Serial.println(temp);
}
}

WIdo联网代码中文注释的更多相关文章

  1. 去掉VS2010代码中文注释的红色下划线

    VS2010代码中文注释出现红色下划线,代码看上去很不美观,发现是由于安装Visual Assist X插件造成的. 解决办法:打开VAX的Options对话框,取消Advanced --> U ...

  2. 关闭shift中英文切换 英文代码/中文注释随意切换着写。

    x 背景 写代码的时候总是意外的就切成中文了,特别是代码中大小写切换的这种情况... 例如:"public static TimeZone CurrentTime..."publi ...

  3. 【caffe Net】使用举例和代码中文注释

    首先是Net使用的小例子: #include <vector> #include <iostream> #include <caffe/net.hpp> using ...

  4. 【caffe I/O】数据读取层 代码中文注释

    caffe.proto中DataParameter部分 message DataParameter { //输入数据使用的DB类型 enum DB { LEVELDB = ;//使用LEVELDB L ...

  5. 【caffe Layer】代码中文注释

    src/caffe/proto/caffe.proto 中LayerParameter部分 // NOTE // Update the next available ID when you add a ...

  6. [转载]将别人的项目或JAVA文件导入到自己的Eclipse中时,常常会出现JAVA文件的中文注释变成乱码的情况,解决办法

    eclipse 代码中文注释乱码 求解决 将别人的项目或JAVA文件导入到自己的Eclipse中时,常常会出现JAVA文件的中文注释变成乱码的情况,主要原因就是别人的IDE编码格式和自己的Eclips ...

  7. mysql代码里面有中文注释导致语法错误

    一个简单的创建表的代码 DROP database IF exists reg_login; CREATE database reg_login; use reg_login --用户表 create ...

  8. Visual Studio vs2010 去掉中文注释红色下划线;去掉代码红色下划线;

    vs去掉下挂线也分两种: 1.去掉中文注释红色下划线,需要去掉VisualAssist下划线鸡肋功能: 1.选择Visual AssistX Options: 2.把如图所示的勾去掉,解决. 以后再次 ...

  9. C++格式化代码,去掉vs2010编辑器里中文注释的红色波浪线

    原文:http://sulianqi.cn/Article/ART2013053100001.html Vs2010中C++没有智能感应提示,不习惯,于是装了个番茄插件(Visual Assist x ...

随机推荐

  1. linux下如何源码编译安装vim

    1. 获取源码 git clone https://github.com/vim/vim.git ~/vim cd ~/vim 2. 配置 ./configure --prefix=/home/jel ...

  2. [shell]输出内容到剪切板

    commandline和GUI下的clipboard的交互Mac下echo $PATH | pbcopy,copy to clipboardecho "$(pbpaste -Prefer t ...

  3. SAP Fiori Client

    iPhone资源->iPhone商务软件 SAP Fiori Client 固件要求:需要 iOS 9.0 或更高版本.与 iPhone.iPad 和 iPod touch 兼容. 利用适用于 ...

  4. js Array​.prototype​.reduce()

    例子: , , , ]; const reducer = (accumulator, currentValue) => accumulator + currentValue; // 1 + 2 ...

  5. kafka生产者

    1.kafka生产者是线程安全的,她允许多个线程共享一个kafka实例 2.kafka管理一个简单的后台线程,所有的IO操作以及与每个broker的tcp连接通信,如果没有正确的关闭生产者可能会造成资 ...

  6. win8获取保存的wlan密码方法

    使用netsh wlan show profile * key=clear 方法查找所有的保存的wifi 使用 netsh wlan show profile name="wifi名字&qu ...

  7. CentOS7.5 Python3安装pip报错:ModuleNotFoundError: No module named '_ctypes' --Python3

    1.问题:pyhontModuleNotFoundError: No module named '_ctypes'  操作系统:CentOS7.5 安装完Pyhotn3后(如何安装Python3,安装 ...

  8. linux——常用命令清单

    目录 文件目录相关命令 压缩命令 关机重启命令 挂载命令 用户登录查看命令 搜索命令的命令 本文整理了学习过程中linux的一些常用操作命令,方便以后查阅.学习的课程是Linux达人养成计划 I. 文 ...

  9. WEB UI做TREE

    效果图: 原本的普通搜索帮助,改成上面这样层级的搜索帮助.这里只做了两级. 一,新建一个TREE节点 1.新建tree结构:ZGRTEXT 2.新建树叶节点处理类: 修改超类为CL_BSP_WD_TR ...

  10. 封装一个使用cURL以POST方式请求https协议的公众方法

    打开php7.2手册,搜索curl function getRequest($url,$type='get', $data = [], $timeout = 10) (需要更改){ $ssl = st ...