使用WIDO连接Yeelink改为OneNet后不定时死机并且自动重新开始.
2016-05-041.7万
AI 快速预览详细
本文讨论了使用WIDO模块连接OneNet平台后出现的不定时死机和自动重新开始的问题。通过详细分析可能的原因,如TCP连接超时和数据发送间隔不合理,提供了解决方案。具体建议包括调整TCP连接超时时间为5000毫秒,并将数据发送间隔设置为3000毫秒,以提高设备的稳定性。此外,还提供了完整的代码示例和调试步骤,帮助用户快速解决问题。
|
因Yeelink不稳定,我用使用WIDO连接Yeelink例程改为链接到OneNet平台,post语句测试,出现运行一段时间后自动停止传输数据,过一段时间后又恢复上传数据。 请问是什么问题?板子不稳定还是程序不稳定?求教高手 ![]() #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); // you can change this clock speed // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 #define WLAN_SECURITY WLAN_SEC_WPA2 #define WLAN_SSID "Tenda_42F538" // cannot be longer than 32 characters! #define WLAN_PASS "31323333" // For connecting router or AP, don't forget to set the SSID and password here!! #define TCP_TIMEOUT 3000 //#define CC3000_TINY_DRIVER #define WEBSITE "api.heclouds.com" #define API_key "Gb=2xmICfmN50mFFZ1vfxxiCVU=" // 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")); /* Initialise the module */ Serial.println(F("\nInitialising the CC3000 ...")); if (!Wido.begin()) { Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); 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! By default connectToAP will retry indefinitely, however you can pass an optional maximum number of retries (greater than zero) as the fourth parameter. */ if (!Wido.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 (!Wido.checkDHCP()) { delay(100); // ToDo: Insert a DHCP timeout! } } 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 Serial.print(F("api.yeelink.net -> ")); while (ip == 0) { if (!Wido.getHostByName(WEBSITE, &ip)) { // Get the server IP address based on the domain name Serial.println(F("Couldn't resolve!")); } delay(500); } Wido.printIPdotsRev(ip); Serial.println(F("")); // Connect to the Yeelink Server 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. // Prepare Http Package for Yeelink & get length int length = 0; char lengthstr[3]; // Create Http data package char httpPackage[5] = ""; /* strcat(httpPackage,"{\"datastreams\":[{\"id\":\"open\",\"datapoints\":[{\"value\":"); itoa(temp,httpPackage+strlen(httpPackage),10); // push the data(temp) to the http data package 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 OneNet server.")); // Send headers Serial.print(F("Sending headers")); WidoClient.fastrprint(F("POST /devices/")); WidoClient.fastrprint(F("108479/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.heclouds.com")); //Serial.print(F(".")); WidoClient.fastrprint(F("api-key:")); WidoClient.fastrprintln(API_key); //Serial.print(F(".")); WidoClient.fastrprintln("Content-Length:60"); //WidoClient.fastrprintln(lengthstr); WidoClient.fastrprintln(""); //Serial.print(F(".")); //Serial.println(F(" done.")); // Send data //Serial.print(F("Sending data")); //WidoClient.fastrprintln(httpPackage); WidoClient.fastrprint(F("{\"datastreams\":")); WidoClient.fastrprint(F("[{\"id\":\"open\",")); WidoClient.fastrprint(F("\"datapoints\":")); WidoClient.fastrprint(F("[{\"value\":")); itoa(temp,httpPackage+strlen(httpPackage),10); WidoClient.fastrprint(httpPackage); WidoClient.fastrprintln(F("}]}]}")); //WidoClient.fastrprintln(API_key); 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); } } |





1.稳定供电,不要用USB供电
2.增加看门狗定时自动重启删除冗余,保证效率最大化(ATMEGA32U4问题0 0)
ps:使用内置看门狗http://www.geek-workshop.com/thread-2413-1-1.html,要不就用专用的芯片DS1232。
3.yeelink现在好像要求上传间隔要大于等于10秒。看看是不是有这个问题
4.试着把发送间隔设长一点看看。
我估计应该是无线网络或者是板子的问题。再次感谢