代码如下“

/***************************************************
*这是一个例子的dfrobot维多-无线集成物联网建兴传感器和控制节点
*产品页面及更多信息:http://www.dfrobot.com.cn/goods-997.html
*特别设计的dfrobot维多产品的工作:
*
*图书馆叉从Adafruit
*
*劳伦写的
* BSD许可证,所有以上文字必须包含在任何重
*
****************************************************/ /*
这个例子的代码是用于连接yeelink云服务(官方主页:www.yeelink .net)。
所需的设备只是:
1。LM35温度传感器的低成本或任何你用来上传数据的装置
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 "myNetwork" // cannot be longer than 32 characters!
#define WLAN_PASS "myPassword" // For connecting router or AP, don't forget to set the SSID and password here!! #define TCP_TIMEOUT 3000
//定义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")); /*初始化模块*/
Serial.println(F("\nInitialising the CC3000 ..."));
if (!Wido.begin())
{
Serial.println(F("无法初始化的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(); // 每个插入的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[]; // 创建HTTP数据包
char httpPackage[] = ""; strcat(httpPackage,"{\"value\":");
itoa(temp,httpPackage+strlen(httpPackage),);
//日期(时间)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.")); // 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
//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();
// read the LM35 sensor value and convert to the degrees every 100ms. int reading = analogRead();
temp = reading *0.0048828125*;
Serial.print(F("Real Time Temp: "));
Serial.println(temp);
}
}

/***************************************************  *这是一个例子的dfrobot维多-无线集成物联网建兴传感器和控制节点*产品页面及更多信息:http://www.dfrobot.com.cn/goods-997.html*特别设计的dfrobot维多产品的工作:**图书馆叉从Adafruit**劳伦写的* BSD许可证,所有以上文字必须包含在任何重 *  ****************************************************/ /*这个例子的代码是用于连接yeelink云服务(官方主页:www.yeelink .net)。所需的设备只是:1。LM35温度传感器的低成本或任何你用来上传数据的装置2。和Wido注意:请不要忘记在使用前更改下面的设置!1。wlan_ssid和wlan_pass2。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       "myNetwork"           // cannot be longer than 32 characters!#define WLAN_PASS       "myPassword"          // For connecting router or AP, don't forget to set the SSID and password here!!

#define TCP_TIMEOUT      3000//定义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(115200);  Serial.println(F("Hello, CC3000!\n"));
  /*初始化模块*/  Serial.println(F("\nInitialising the CC3000 ..."));  if (!Wido.begin())  {    Serial.println(F("无法初始化的CC3000!检查你的线路?"));    while(1);  }
  /* 尝试连接到接入点 */  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(1);  }
  Serial.println(F("Connected!"));
  /*等待DHCP完成 */  Serial.println(F("Request DHCP"));  while (!Wido.checkDHCP())  {    delay(100); // 每个插入的DHCP:超时!  }  
}
uint32_t ip = 0;float temp = 0;
void loop(){    static Adafruit_CC3000_Client WidoClient;  static unsigned long RetryMillis = 0;  static unsigned long uploadtStamp = 0;  static unsigned long sensortStamp = 0;
  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  ==  0)  {      if  (!Wido.getHostByName(WEBSITE, &ip))  {    //  Get the server IP address based on the domain name       //根据域名获取服务器IP地址        Serial.println(F("Couldn't resolve!"));      }      delay(500);    }      Wido.printIPdotsRev(ip);    Serial.println(F(""));        // Connect to the Yeelink Server连接到服务器的yeelink    WidoClient = Wido.connectTCP(ip, 80);          // Try to connect cloud server尝试连接云服务器  }    if(WidoClient.connected() && millis() - uploadtStamp > 2000){    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 = 0;    char lengthstr[3];        // 创建HTTP数据包    char httpPackage[60] = "";        strcat(httpPackage,"{\"value\":");    itoa(temp,httpPackage+strlen(httpPackage),10);              //日期(时间)Push the to the HTTP数据包    strcat(httpPackage,"}");        length = strlen(httpPackage);                           // get the length of data package    itoa(length,lengthstr,10);                              // convert int to char array for posting    Serial.print(F("Length = "));    Serial.println(length);        Serial.println(F("Connected to Yeelink server."));        // 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                                                           //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 < 2000) {      while (WidoClient.connected() && WidoClient.available()) {        char c = WidoClient.read();        Serial.print(c);      }    }    delay(1000);             // 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 > 1000){    sensortStamp = millis();    // read the LM35 sensor value and convert to the degrees every 100ms.
    int reading = analogRead(0);    temp = reading *0.0048828125*100;    Serial.print(F("Real Time Temp: "));     Serial.println(temp);   }}

CC3000 Arduino 连接Yeelink中文注释 示例的更多相关文章

  1. arduino 522样本中文注释

    #accesscontrol访问控制#change uid更改UID#dump info转储信息#firmware_check固件#Fix Bricked UID修复变砖的UID#Mifare Cla ...

  2. 在使用Arduino中遇到的问题(无法使用中文注释、程序无法下载)

    在使用Arduino中遇到的问题: 在用arduino给蓝牙模块供电时,下载程序是下不进去的.即使显示下进去了,其实也是没下进去. 解决方法:拔掉蓝牙模块再下程序,或给蓝牙供电的线上加上一个开关. 在 ...

  3. WIdo联网代码中文注释

    代码如下 /*************************************************** 这是一个例子的dfrobot维多-无线集成物联网建兴传感器和控制节点 *产品页面及更 ...

  4. Php.ini 中文注释详细

    Php.ini 中文注释 这个文件控制了PHP许多方面的观点.为了让PHP读取这个文件,它必须被命名为   ; ´php.ini´.PHP 将在这些地方依次查找该文件:当前工作目录:环境变量PHPRC ...

  5. 一个非常标准的连接Mysql数据库的示例代码

    一.About Mysql 1.Mysql 优点 体积小.速度快.开放源码.免费 一般中小型网站的开发都选择 MySQL ,最流行的关系型数据库 LAMP / LNMP Linux作为操作系统 Apa ...

  6. 【原创】大叔经验分享(34)hive中文注释乱码

    在hive中查看表结构时中文注释乱码,分为两种情况,一种是desc $table,一种是show create table $table 1 数据库字符集 检查 mysql> show vari ...

  7. 关于iBatis配置xml文件时出现中文注释出错的一个问题(很坑爹.)

    才开始我没有使用SqlMap.properties来配置连接信息.所以直接用ctrl + shift + C然后往里面添加的中文注释 例: <!-- 注释--> 运行的时候报: Error ...

  8. Tensoflw.js - 01 - 安装与入门(中文注释)

    Tensoflw.js - 01 - 安装与入门(中文注释) 参考 W3Cschool 文档:https://www.w3cschool.cn/tensorflowjs/ 本文主要翻译一些英文注释,添 ...

  9. Arduino连接pH计

    关于arduino连接ph,核心的东西就是对ph传感器返回的信号值进行一系列的操作,注意因为返回的信号很弱,而且外部环境对其影响也很大,所以需要在电路设计上加入一些功能,比如信号放大.滤波等,电路设计 ...

随机推荐

  1. (转载)Unity学习笔记:关于Dropdown的学习

    今天组长让我写一个界面,其中用到了下拉条,我的印象还停留在以前的NGUI有现成的组件,但是uGUI没有的那阶段,组长跟我说uGUI现在也有了,研究了一下,发现real方便哦,今天就来简单说一下用法吧. ...

  2. variable 'o' used without having been completely initialized Compiling Vertex program

    variable 'o' used without having been completely initialized Compiling Vertex program   v2f vert (ap ...

  3. Angular 学习笔记 (久久没有写 angular 常会忘记的小细节)

    由于经常跑去写后端, 而且一些就几个月...很多 ng 的东西就忘掉了. 写在这里方便复习呗. 1. async pipe 没有 resolve 前返回的值是 null 2 view componen ...

  4. Django Context对象 + 过滤器 + 标签

    玩一玩上下文(context)对象 多数时间,你可以通过传递一个完全填充(full populated)的字典给 Context() 来初始化 上下文(Context) . 但是初始化以后,你也可以从 ...

  5. [Spring MVC] 表单提交日期转换问题,比如可能导致封装实体类时400错误

    三种格式的InitBinder @InitBinder//https://stackoverflow.com/questions/20616319/the-request-sent-by-the-cl ...

  6. C#中Equals和= =(等于号)的比较)

    C#中Equals和= =(等于号)的比较) 相信很多人都搞不清Equals和 = =的区别,只是零星的懂一点,现在就让我带大家来进行一些剖析 一.           值类型的比较 对于值类型来说  ...

  7. arrow function、function.apply

    An arrow function expression has a shorter syntax than a function expression and does not have its o ...

  8. Jquery获取元素方法

    Jquery 获取元素的方法分为两种:jQuery选择器.jQuery遍历函数. 1.获取本身: a.只需要一种jQuery选择器 选择器 实例 说明 #Id $('#myId') ID选择器: 可以 ...

  9. 如何设置IntelliJ IDEA智能感知支持Jsp内置对象

    一.问题: 在IntelliJ IDEA 新建jsp页面,想通过内置对象获取查询参数,比如:request.getParameter("id"),虽然手动输入后能够运行成功,但是智 ...

  10. kafka producer 发送消息简介

    kafka 的 topic 由 partition 组成,producer 会根据 key,选择一个 partition 发送消息,而 partition 有多个副本,副本有 leader 和 fol ...