为什么我的程序上传到8266blinker就不能连接,而blinker例程就可以- 下面是我的程序double Fahrenheit(double celsius)
- {
- return 1.8 * celsius + 32;
- } //摄氏温度度转化为华氏温度
- double Kelvin(double celsius)
- {
- return celsius + 273.15;
- } //摄氏温度转化为开氏温度
- // 露点(点在此温度时,空气饱和并产生露珠)
- // 参考: http://wahiduddin.net/calc/density_algorithms.htm
- double dewPoint(double celsius, double humidity)
- {
- double A0= 373.15/(273.15 + celsius);
- double SUM = -7.90298 * (A0-1);
- SUM += 5.02808 * log10(A0);
- SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
- SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
- SUM += log10(1013.246);
- double VP = pow(10, SUM-3) * humidity;
- double T = log(VP/0.61078); // temp var
- return (241.88 * T) / (17.558-T);
- }
- // 快速计算露点,速度是5倍dewPoint()
- // 参考: http://en.wikipedia.org/wiki/Dew_point
- double dewPointFast(double celsius, double humidity)
- {
- double a = 17.271;
- double b = 237.7;
- double temp = (a * celsius) / (b + celsius) + log(humidity/100);
- double Td = (b * temp) / (a - temp);
- return Td;
- }
- #define BLINKER_PRINT Serial
- #define BLINKER_WIFI
- #include <Blinker.h>
- #include <dht11.h>
- dht11 DHT11;
- #define DHT11PIN 2
- char ssid[]="Tenda_299C18";//名称
- char pswd[]="13715860937";//密码
- #define BUTTON_1 "a"//控制水泵的按钮
- #define BUTTON_2 "e"
- #define BUTTON_3 "f"
- #define KG_1 "b"//切换模式的按钮
- #define KG_2 "c"//在较干燥的的时候才浇水按钮
- #define KG_3 "d"//与kg3相反
- int a=5;//水泵定义
- int b=A0;//土壤传感器定义
- int c=6;//温湿度传感器定义
- int l=7;//电源灯定义
- int x=0;//变量
- int y=0;//变量
- void ZD(){
- x=analogRead(b);
- if(x>=630&&x<=750){
- digitalWrite(a,HIGH);
- }else{
- digitalWrite(a,LOW);
- }
- }
- void S(){
- if(Blinker.button(BUTTON_1)){
- digitalWrite(a,HIGH);
- }else{
- digitalWrite(a,HIGH);
- }
- }
- void WS(){
- Blinker.println("\n");
- int chk = DHT11.read(DHT11PIN);
- Blinker.print("Read sensor: ");
- switch (chk)
- {
- case DHTLIB_OK:
- Blinker.println("OK");
- break;
- case DHTLIB_ERROR_CHECKSUM:
- Blinker.println("Checksum error");
- break;
- case DHTLIB_ERROR_TIMEOUT:
- Blinker.println("Time out error");
- break;
- default:
- Blinker.println("Unknown error");
- break;
- }
- Blinker.print("Humidity (%): ");
- Blinker.println((float)DHT11.humidity, 2);
- Blinker.print("Temperature (oC): ");
- Blinker.println((float)DHT11.temperature, 2);
- Blinker.print("Temperature (oF): ");
- Blinker.println(Fahrenheit(DHT11.temperature), 2);
- Blinker.print("Temperature (K): ");
- Blinker.println(Kelvin(DHT11.temperature), 2);
- Blinker.print("Dew Point (oC): ");
- Blinker.println(dewPoint(DHT11.temperature, DHT11.humidity));
- Blinker.print("Dew PointFast (oC): ");
- Blinker.println(dewPointFast(DHT11.temperature, DHT11.humidity));
- }
- void TU(){
- x=analogRead(b);
- if(x>=630&&x<=750){
- Blinker.println("Current soil moisture is normal");
- }
- if(x>750&&x<=920){
- Blinker.println("The soil is dry at present");
- }
- if(x>=420&&x<630){
- Blinker.println("The soil is moist now");
- }
- if(x<420){
- Blinker.println("The current sensor is completely underwater");
- }
- if(x>920){
- Blinker.println("Please check if your sensor is in the flowerpot");
- }
- }
- void setup()
- {
- Serial.begin(115200);
- pinMode(a,OUTPUT);
- pinMode(b,INPUT);
- pinMode(c,INPUT);
- pinMode(l,OUTPUT);
- Blinker.begin(ssid, pswd);
- Blinker.wInit(BUTTON_1, W_BUTTON);
- Blinker.wInit(BUTTON_2, W_BUTTON);
- Blinker.wInit(BUTTON_3, W_BUTTON);
- Blinker.wInit(KG_1,W_TOGGLE);
- Blinker.wInit(KG_2,W_TOGGLE);
- Blinker.wInit(KG_3,W_TOGGLE);
- }
- void loop()
- {
- Blinker.run();
- if (Blinker.available()) {
- BLINKER_LOG2("Blinker.readString(): ", Blinker.readString());
- Blinker.vibrate();
- uint32_t BlinkerTime = millis();
- Blinker.print(BlinkerTime);
- Blinker.print("millis", BlinkerTime);}
- if(Blinker.toggle(KG_1)){
- ZD();
- }else{
- S();
- }
- if(Blinker.button(BUTTON_2)){
- WS();}
- if(Blinker.button(BUTTON_3)){
- TU();
- }
- }
复制代码
|