极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12939|回复: 0

uno+w5100+乐联+sht1x 远程监控温湿度的问题

[复制链接]
发表于 2016-4-11 12:42:34 | 显示全部楼层 |阅读模式
本帖最后由 liule126 于 2016-4-11 14:31 编辑

如题,搭建一个远程监控的小系统,但是数据始终上传不到乐联网,串口显示“connect failed”。以下是代码和串口的显示,各位大神帮帮忙分析一下哪里错误了,是网络不通还是程序有问题啊
跪谢!!!
------------------代码:
/*
   lewei50 open platform sensor client
   This code is in the public domain.
  */

#include <LeweiClient.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SHT1x.h>
#define LW_USERKEY "2c0e0a9e27d64c7f96b73a1e285c93b4"
#define LW_GATEWAY "01"
#define dataPin  6
#define clockPin 7
SHT1x sht1x(dataPin, clockPin);
//delay between updates
#define POST_INTERVAL (30*1000)


IPAddress ip(10,33,52,241);
IPAddress mydns(192,168,100,6);
IPAddress gw(10,33,52,1);
IPAddress subnet(255,255,255,0);

LeWeiClient *lwc;


void setup() {
   // start serial port:
   Serial.begin(9600);
   // hope no exception here
   Serial.println("Starting up");
   //lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY);
   lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,ip,mydns,gw,subnet);
}

void loop() {
   // read the analog sensor:
   //int sensorReading = analogRead(A0);  
  float temp_c;
  //float temp_f;
  float humidity;
  temp_c = sht1x.readTemperatureC();
  //temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();
  Serial.print("Temperature: ");
  Serial.print(temp_c, DEC);
  Serial.print("C / ");
  //Serial.print(temp_f, DEC);
  //Serial.print("F. Humidity: ");
  Serial.print(humidity);
  Serial.println("%");
  // if there's incoming data from the net connection.
   // send it out the serial port.  This is for debugging
   // purposes only:

  if (lwc) {
    Serial.print("*** start data collection ");
   
    //t1,t2.. must using the same name setting on web server.
    lwc->append("GGT1", temp_c);
    lwc->append("GGH1", humidity);
    Serial.print("*** data send ***");
    lwc->send();
    //Grammar changed by Wei&Anonymous ;)
    Serial.print("*** send completed ***");

   delay(POST_INTERVAL);
   }
}
串口反馈的信息,总显示connect failed
串口信息:
Starting up
Temperature: 27.8799972534C / 28.13%
*** start data collection append:{"Name":"GGT1","Value":"27.88"},
append:{"Name":"GGH1","Value":"28.13"},
*** data send ***connect failed!
*** send completed ***
参考资料:
http://blog.sina.com.cn/s/blog_66fa66650102wa4z.html
乐联的库https://github.com/lewei50/LeweiClient
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 17:25 , Processed in 0.102103 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表