上传数据到yeelink时总是提示failed connect
用的是seeeduino的板和seeeduino的wifi shield RN171按照产品提供的例程上传传感器数据到yeelink,可是总是提示failed connect,请各位大咖帮我看看哪里不对好吗(。´・ω・`)
这是代码
#include <math.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <WiFly.h>
#include "HTTPClient.h"
#define SSID "这不是你的WiFi"
#define KEY "1234567890"
#define AUTH WIFLY_AUTH_WPA2_PSK // WIFLY_AUTH_WPA1, WIFLY_AUTH_WEP, WIFLY_AUTH_OPEN
#define HTTP_POST_HEADERS "U-ApiKey:686fc75226ee61988f95ccf609bef8b6\r\n"
#define HTTP_POST_URL "http://api.yeelink.net/v1.0/device/14993/sensor/25699/datapoints"
const int temsensor=A0;
int a;
float temperature;
int B=3975;
float resistance;
SoftwareSerial uart(2, 3);
WiFly wifly(uart);
HTTPClient http;//建一个HTTPClient的对象http
char get;
void setup()
{
Wire.begin(9600);
uart.begin(9600);
Serial.begin(9600);
Serial.println("------- WIFLY HTTP --------");
Serial.println("Try to join " SSID"...");
if (!wifly.isAssociated(SSID)) {
while (!wifly.join(SSID, KEY, AUTH)) {
Serial.println("Failed to join " SSID);
Serial.println("Wait 1 second and try again...");
}
wifly.save(); // save configuration
}// check if WiFly is associated with AP(SSID)
Serial.println("Connected to " SSID"!\n");
}
unsigned long start_millis = 0;
char post_data_buf;
void loop()
{
if ((millis() - start_millis) < 20000) {
return;
} else {
start_millis = millis();
}
a=analogRead(temsensor);
resistance=(float)(1023-a)*10000/a;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
Serial.print("Current temperature is ");
Serial.println(temperature);
Serial.println("\r\n\r\nTry to post data to url - " HTTP_POST_URL);
Serial.println("-------------------------------");
int whole=int(temperature);int fract=int(temperature*100)%100;
snprintf(post_data_buf, sizeof(post_data_buf), "{\"value\": %d.%d}\r\n",whole,fract+1);
Serial.println(post_data_buf);
while (http.post(HTTP_POST_URL, HTTP_POST_HEADERS, post_data_buf,10000) < 0){}
char r;
while (wifly.receive((uint8_t *)&r, 1, 1000) == 1) {
Serial.print(r);
}
delay(10000);
}
就是执行到倒数第七行的时候提示failed connect
然后我看了下 HTTPClient.cpp
找到了failed connect的原因
if (!wifly->connect(host, port, timeout)) {
DBG("Failed to connect.\r\n");
可是看不懂事什么意思_(:з」∠)_
页:
[1]