pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      <i id='XZUha'><tr id='XZUha'><dt id='XZUha'><q id='XZUha'><span id='XZUha'><b id='XZUha'><form id='XZUha'><ins id='XZUha'></ins><ul id='XZUha'></ul><sub id='XZUha'></sub></form><legend id='XZUha'></legend><bdo id='XZUha'><pre id='XZUha'><center id='XZUha'></center></pre></bdo></b><th id='XZUha'></th></span></q></dt></tr></i><div class="mqyeau0" id='XZUha'><tfoot id='XZUha'></tfoot><dl id='XZUha'><fieldset id='XZUha'></fieldset></dl></div>

        <legend id='XZUha'><style id='XZUha'><dir id='XZUha'><q id='XZUha'></q></dir></style></legend>
      1. <small id='XZUha'></small><noframes id='XZUha'>

        <tfoot id='XZUha'></tfoot>
          <bdo id='XZUha'></bdo><ul id='XZUha'></ul>

      2. Arduino UNO, CC3000: while(client.connected)

        Arduino UNO, CC3000: while(client.connected)(Arduino UNO, CC3000: while(client.connected))

          <tfoot id='8pJzF'></tfoot>
            <bdo id='8pJzF'></bdo><ul id='8pJzF'></ul>
          • <i id='8pJzF'><tr id='8pJzF'><dt id='8pJzF'><q id='8pJzF'><span id='8pJzF'><b id='8pJzF'><form id='8pJzF'><ins id='8pJzF'></ins><ul id='8pJzF'></ul><sub id='8pJzF'></sub></form><legend id='8pJzF'></legend><bdo id='8pJzF'><pre id='8pJzF'><center id='8pJzF'></center></pre></bdo></b><th id='8pJzF'></th></span></q></dt></tr></i><div class="gmqougo" id='8pJzF'><tfoot id='8pJzF'></tfoot><dl id='8pJzF'><fieldset id='8pJzF'></fieldset></dl></div>
              1. <legend id='8pJzF'><style id='8pJzF'><dir id='8pJzF'><q id='8pJzF'></q></dir></style></legend>

                  <tbody id='8pJzF'></tbody>

                <small id='8pJzF'></small><noframes id='8pJzF'>

                • 本文介紹了Arduino UNO, CC3000: while(client.connected)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在使用連接到遠(yuǎn)程 Web 服務(wù)的 Arduino UNO 和 CC3000 擴(kuò)展板.雖然我在循環(huán)腳本時遇到了問題.正如您在下面的代碼中看到的,腳本應(yīng)該每 5 秒以 occupied 的狀態(tài) ping 網(wǎng)絡(luò)服務(wù).盡管在使用 while(client.connected) 時,有些東西會使 Arduino 永遠(yuǎn)停止/掛起.即使 while(client.connected) {} 只是空的.

                  I'm playing around with an Arduino UNO and a CC3000 shield connecting to a remote web service. Though I'm having a problem looping the script. As you can see in the code below, the script should ping the web service with the state of occupied every 5 seconds. Though when using while(client.connected) something makes the Arduino stop/hang forever. Even if the while(client.connected) {} is just empty.

                  如果我不包含 while(client.connected){},則不會 ping 網(wǎng)絡(luò)服務(wù),這就是我發(fā)現(xiàn)自己處于兩難境地的原因.請參閱下面的 Arduino Sketch 文件和下面的串行日志.

                  If I don't include the while(client.connected){} the web service is not pinged, which is why I find myself in quite a dilemma. Please see Arduino Sketch file below and serial log below that.

                  #include <Adafruit_CC3000.h>
                  #include <ccspi.h>
                  #include <SPI.h>
                  #include <string.h>
                  #include "utility/debug.h"
                  
                  // These are the interrupt and control pins
                  #define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
                  // These can be any two pins
                  #define ADAFRUIT_CC3000_VBAT  5
                  #define ADAFRUIT_CC3000_CS    10
                  // Use hardware SPI for the remaining pins
                  // On an UNO, SCK = 13, MISO = 12, and MOSI = 11
                  Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                  SPI_CLOCK_DIV2); // you can change this clock speed but DI
                  
                  #define WLAN_SSID       "WIFI"        // cannot be longer than 32 characters!
                  #define WLAN_PASS       "WIFI_PW"
                  // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
                  #define WLAN_SECURITY   WLAN_SEC_WPA2
                  
                    uint32_t ip;
                  
                    int ledPin = 8;   // choose the pin for the LED
                    int ledPinSecond = 7;  
                    int inputPin = 2;              // choose the input pin (for PIR sensor)
                    int pirState = LOW;             // we start, assuming no motion detected
                    int val = 0;   // variable for reading the pin status
                    String occupied;   
                  
                  /**************************************************************************/
                  /*!
                   @brief  Sets up the HW and the CC3000 module (called automatically
                   on startup)
                   */
                  /**************************************************************************/
                  void setup(void)
                  {
                    Serial.begin(115200);
                    Serial.println(F("Hello, CC3000!\n")); 
                  
                    displayDriverMode();
                    Serial.print("Free RAM: "); 
                    Serial.println(getFreeRam(), DEC);
                  
                    pinMode(ledPin, OUTPUT);    // declare LED as output
                    pinMode(ledPinSecond, OUTPUT);    
                    pinMode(inputPin, INPUT);     // declare sensor as input 
                  
                    /* Initialise the module */
                    Serial.println(F("\nInitialising the CC3000 ..."));
                    if (!cc3000.begin())
                    {
                      Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
                      while(1);
                    }
                  
                    /* Optional: Update the Mac Address to a known value */
                    /*
                    uint8_t macAddress[6] = { 0x08, 0x00, 0x28, 0x01, 0x79, 0xB7 };
                     if (!cc3000.setMacAddress(macAddress))
                     {
                     Serial.println(F("Failed trying to update the MAC address"));
                     while(1);
                     }
                     */
                  
                    uint16_t firmware = checkFirmwareVersion();
                    if ((firmware != 0x113) && (firmware != 0x118)) {
                      Serial.println(F("Wrong firmware version!"));
                      for(;;);
                    }
                  
                    displayMACAddress();
                  
                    /* Delete any old connection data on the module */
                    Serial.println(F("\nDeleting old connection profiles"));
                    if (!cc3000.deleteProfiles()) {
                      Serial.println(F("Failed!"));
                      while(1);
                    }
                  
                    /* Attempt to connect to an access point */
                    char *ssid = WLAN_SSID;             /* Max 32 chars */
                    Serial.print(F("\nAttempting to connect to ")); 
                    Serial.println(ssid);
                  
                    /* NOTE: Secure connections are not available in 'Tiny' mode! */
                    if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
                      Serial.println(F("Failed!"));
                      while(1);
                    }
                  
                    Serial.println(F("Connected!"));
                  
                    /* Wait for DHCP to complete */
                    Serial.println(F("Request DHCP"));
                    while (!cc3000.checkDHCP())
                    {
                      delay(1000); // ToDo: Insert a DHCP timeout!
                    }  
                  
                    /* Display the IP address DNS, Gateway, etc. */
                    while (! displayConnectionDetails()) {
                      delay(1000);
                    }
                  
                  #ifndef CC3000_TINY_DRIVER    
                    /* Try looking up the webservice */
                    Serial.print(F("www.webservice.com -> "));
                    if (! cc3000.getHostByName("www.webservice.com", &ip)) {
                      Serial.println(F("Could not resolve!"));
                    } 
                    else {
                      cc3000.printIPdotsRev(ip);
                    }
                  
                    Serial.print(F("\n\rPinging ")); 
                    cc3000.printIPdotsRev(ip); 
                    Serial.print("...");  
                    uint8_t replies = cc3000.ping(ip, 5);
                    Serial.print(replies); 
                    Serial.println(F(" replies"));
                    if (replies)
                      Serial.println(F("Ping successful!"));
                  #endif
                  
                    /* You need to make sure to clean up after yourself or the CC3000 can freak out */
                    /* the next time you try to connect ... */
                  //  Serial.println(F("\n\nClosing the connection"));
                  //  cc3000.disconnect();
                  }
                  
                  void loop(void)
                  {
                   val = digitalRead(inputPin);  // read input value
                  
                    occupied = "Occupied";
                    Serial.print("Room state: ");
                    Serial.println(occupied);
                  
                   sendGET();
                   delay(5000);
                  }
                  
                  void sendGET() //client function to send/receive GET request data.
                  {
                      Serial.print(F("Initializing SendGET request\n"));
                       Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
                      char serverName[] = "www.webservice.com"; //webservice host 
                      if (client.connect(serverName, 80)) {
                      //starts client connection, checks for connection
                      Serial.print(F("Adding state to DB\n"));
                      client.println("GET /folder/sensor.php?occupied="+ occupied +" HTTP/1.1"); //download text
                      client.println("Host: webservice.com");
                      client.println("Connection: close");  //close 1.1 persistent connection  
                      client.println(); //end of get request
                      Serial.print(F("Ending connection to DB\n"));
                    } else {
                      Serial.println("Connection to server failed"); //error message if no client connect
                      Serial.println();
                    }
                  
                    Serial.print(F("Checking connection for bytes\n"));
                    while (client.connected()) {
                    while (client.available()) {
                    //Read answer
                    char c = client.read();
                      }
                    }
                  
                    Serial.print(F("Checked for bytes\n"));
                    Serial.print("disconnecting.");
                    Serial.print("==================");
                    client.close(); //stop client
                  
                    }
                  
                  /**************************************************************************/
                  /*!
                   @brief  Displays the driver mode (tiny of normal), and the buffer
                   size if tiny mode is not being used
                  
                   @note   The buffer size and driver mode are defined in cc3000_common.h
                   */
                  /**************************************************************************/
                  void displayDriverMode(void)
                  {
                  #ifdef CC3000_TINY_DRIVER
                    Serial.println(F("CC3000 is configure in 'Tiny' mode"));
                  #else
                    Serial.print(F("RX Buffer : "));
                    Serial.print(CC3000_RX_BUFFER_SIZE);
                    Serial.println(F(" bytes"));
                    Serial.print(F("TX Buffer : "));
                    Serial.print(CC3000_TX_BUFFER_SIZE);
                    Serial.println(F(" bytes"));
                  #endif
                  }
                  
                  /**************************************************************************/
                  /*!
                   @brief  Tries to read the CC3000's internal firmware patch ID
                   */
                  /**************************************************************************/
                  uint16_t checkFirmwareVersion(void)
                  {
                    uint8_t major, minor;
                    uint16_t version;
                  
                  #ifndef CC3000_TINY_DRIVER  
                    if(!cc3000.getFirmwareVersion(&major, &minor))
                    {
                      Serial.println(F("Unable to retrieve the firmware version!\r\n"));
                      version = 0;
                    }
                    else
                    {
                      Serial.print(F("Firmware V. : "));
                      Serial.print(major); 
                      Serial.print(F(".")); 
                      Serial.println(minor);
                      version = major; 
                      version <<= 8; 
                      version |= minor;
                    }
                  #endif
                    return version;
                  }
                  
                  /**************************************************************************/
                  /*!
                   @brief  Tries to read the 6-byte MAC address of the CC3000 module
                   */
                  /**************************************************************************/
                  void displayMACAddress(void)
                  {
                    uint8_t macAddress[6];
                  
                    if(!cc3000.getMacAddress(macAddress))
                    {
                      Serial.println(F("Unable to retrieve MAC Address!\r\n"));
                    }
                    else
                    {
                      Serial.print(F("MAC Address : "));
                      cc3000.printHex((byte*)&macAddress, 6);
                    }
                  }
                  
                  
                  /**************************************************************************/
                  /*!
                   @brief  Tries to read the IP address and other connection details
                   */
                  /**************************************************************************/
                  bool displayConnectionDetails(void)
                  {
                    uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
                  
                    if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
                    {
                      Serial.println(F("Unable to retrieve the IP Address!\r\n"));
                      return false;
                    }
                    else
                    {
                      Serial.print(F("\nIP Addr: ")); 
                      cc3000.printIPdotsRev(ipAddress);
                      Serial.print(F("\nNetmask: ")); 
                      cc3000.printIPdotsRev(netmask);
                      Serial.print(F("\nGateway: ")); 
                      cc3000.printIPdotsRev(gateway);
                      Serial.print(F("\nDHCPsrv: ")); 
                      cc3000.printIPdotsRev(dhcpserv);
                      Serial.print(F("\nDNSserv: ")); 
                      cc3000.printIPdotsRev(dnsserv);
                      Serial.println();
                      return true;
                    }
                  }
                  

                  日志

                    Hello, CC3000!
                  
                      RX Buffer : 131 bytes
                      TX Buffer : 131 bytes
                      Free RAM: 1047
                  
                      Initialising the CC3000 ...
                      Firmware V. : 1.24
                      MAC Address : MAC_ADDRESS
                  
                      Deleting old connection profiles
                  
                      Attempting to connect to 64 Allen Street - East
                      Connected!
                      Request DHCP
                  
                      IP Addr: XXX.XXX.XX.X
                      Netmask: 255.255.255.0
                      Gateway: 192.168.0.1
                      DHCPsrv: 192.168.0.1
                      DNSserv: XXX.XX.X.X
                      www.webservice.com -> XX.XX.XXX.XXX
                  
                      Pinging XX.XX.XXX.XXX...5 replies
                      Ping successful!
                      Room state: Free
                      Initializing SendGET request
                      Adding state to DB
                      Ending connection to DB
                      Checking connection for bytes
                  

                  推薦答案

                  為什么不將用于已連接客戶端的代碼移動到您連接的 if 語句中.那么你就不需要輪詢 client.connected() 函數(shù).

                  Why not move the code that is for a connected client into the if statement where you connect. Then you do not need to poll the client.connected() function.

                  這個邏輯好像有問題.如果客戶端已連接,它可能會保持連接狀態(tài),直到循環(huán)下方的行:client.close(); 這將導(dǎo)致循環(huán)永遠(yuǎn)不會結(jié)束.

                  It seems the logic is flawed. If a client is connected, it will probably remain connected until the line you have below the loop: client.close(); Which would cause the loop to never end.

                  或者,您也可以在循環(huán)中添加一些代碼以防止它永遠(yuǎn)運行.

                  Alternatively you could also add some code inside the loop to prevent it from running for ever.

                  uint32_t theTime = millis();
                  
                  while(client.connected()){
                    if( ( millis() - theTime ) >1000 ) break;  //exit loop after one second.
                  }
                  

                  這篇關(guān)于Arduino UNO, CC3000: while(client.connected)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數(shù)根據(jù) N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達(dá)式的結(jié)果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數(shù)的 ignore 選項是忽略整個事務(wù)還是只是有問題的行?) - IT屋-程序員軟件開發(fā)技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環(huán)數(shù)組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調(diào)用 o23.load 時發(fā)生錯誤 沒有合適的驅(qū)動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數(shù)據(jù)庫表作為 Spark 數(shù)據(jù)幀讀取?)
                  <i id='77suR'><tr id='77suR'><dt id='77suR'><q id='77suR'><span id='77suR'><b id='77suR'><form id='77suR'><ins id='77suR'></ins><ul id='77suR'></ul><sub id='77suR'></sub></form><legend id='77suR'></legend><bdo id='77suR'><pre id='77suR'><center id='77suR'></center></pre></bdo></b><th id='77suR'></th></span></q></dt></tr></i><div class="yawec22" id='77suR'><tfoot id='77suR'></tfoot><dl id='77suR'><fieldset id='77suR'></fieldset></dl></div>

                  1. <legend id='77suR'><style id='77suR'><dir id='77suR'><q id='77suR'></q></dir></style></legend>
                      <tbody id='77suR'></tbody>

                    • <bdo id='77suR'></bdo><ul id='77suR'></ul>

                      <small id='77suR'></small><noframes id='77suR'>

                          <tfoot id='77suR'></tfoot>

                            主站蜘蛛池模板: 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 讲师宝经纪-专业培训机构师资供应商_培训机构找讲师、培训师、讲师经纪就上讲师宝经纪 | WF2户外三防照明配电箱-BXD8050防爆防腐配电箱-浙江沃川防爆电气有限公司 | 烟气换热器_GGH烟气换热器_空气预热器_高温气气换热器-青岛康景辉 | 日本细胞免疫疗法_肿瘤免疫治疗_NK细胞疗法 - 免疫密码 | HDPE土工膜,复合土工膜,防渗膜价格,土工膜厂家-山东新路通工程材料有限公司 | 中国品牌门窗网_中国十大门窗品牌_著名门窗品牌 | 土壤养分检测仪_肥料养分检测仪_土壤水分检测仪-山东莱恩德仪器 大型多片锯,圆木多片锯,方木多片锯,板材多片锯-祥富机械有限公司 | 黑龙江京科脑康医院-哈尔滨精神病医院哪家好_哈尔滨精神科医院排名_黑龙江精神心理病专科医院 | 武汉高低温试验机-现货恒温恒湿试验箱-高低温湿热交变箱价格-湖北高天试验设备 | 小型数控车床-数控车床厂家-双头数控车床 | 仓储笼_仓储货架_南京货架_仓储货架厂家_南京货架价格低-南京一品仓储设备制造公司 | 智能家居全屋智能系统多少钱一套-小米全套价格、装修方案 | 盐城网络公司_盐城网站优化_盐城网站建设_盐城市启晨网络科技有限公司 | 电动卫生级调节阀,电动防爆球阀,电动软密封蝶阀,气动高压球阀,气动对夹蝶阀,气动V型调节球阀-上海川沪阀门有限公司 | 老房子翻新装修,旧房墙面翻新,房屋防水补漏,厨房卫生间改造,室内装潢装修公司 - 一修房屋快修官网 | 有机肥设备生产制造厂家,BB掺混肥搅拌机、复合肥设备生产线,有机肥料全部加工设备多少钱,对辊挤压造粒机,有机肥造粒设备 -- 郑州程翔重工机械有限公司 | 硫酸钡厂家_高光沉淀硫酸钡价格-河南钡丰化工有限公司 | 哈尔滨治「失眠/抑郁/焦虑症/精神心理」专科医院排行榜-京科脑康免费咨询 一对一诊疗 | 海峰资讯 - 专注装饰公司营销型网站建设和网络营销培训 | 校服厂家,英伦校服定做工厂,园服生产定制厂商-东莞市艾咪天使校服 | 塑料造粒机「厂家直销」-莱州鑫瑞迪机械有限公司 | 移动机器人产业联盟官网 | 石家庄小程序开发_小程序开发公司_APP开发_网站制作-石家庄乘航网络科技有限公司 | 3d打印服务,3d打印汽车,三维扫描,硅胶复模,手板,快速模具,深圳市精速三维打印科技有限公司 | 电动车头盔厂家_赠品头盔_安全帽批发_山东摩托车头盔—临沂承福头盔 | 房在线-免费房产管理系统软件-二手房中介房屋房源管理系统软件 | FAG轴承,苏州FAG轴承,德国FAG轴承-恩梯必传动设备(苏州)有限公司 | 掺铥光纤放大器-C/L波段光纤放大器-小信号光纤放大器-合肥脉锐光电技术有限公司 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 | 南京交通事故律师-专打交通事故的南京律师 | 东莞市踏板石餐饮管理有限公司_正宗桂林米粉_正宗桂林米粉加盟_桂林米粉加盟费-东莞市棒子桂林米粉 | 冷热冲击试验箱_温度冲击试验箱价格_冷热冲击箱排名_林频厂家 | 上海乾拓贸易有限公司-日本SMC电磁阀_德国FESTO电磁阀_德国FESTO气缸 | 品牌策划-品牌设计-济南之式传媒广告有限公司官网-提供品牌整合丨影视创意丨公关活动丨数字营销丨自媒体运营丨数字营销 | 美缝剂_美缝剂厂家_美缝剂加盟-地老板高端瓷砖美缝剂 | NBA直播_NBA直播免费观看直播在线_NBA直播免费高清无插件在线观看-24直播网 | 江西高职单独招生-江西单招考试-江西高职单招网 | 复合土工膜厂家|hdpe防渗土工膜|复合防渗土工布|玻璃纤维|双向塑料土工格栅-安徽路建新材料有限公司 | 江苏全风,高压风机,全风环保风机,全风环形高压风机,防爆高压风机厂家-江苏全风环保科技有限公司(官网) | 便携式高压氧舱-微压氧舱-核生化洗消系统-公众洗消站-洗消帐篷-北京利盟救援 |