我做了一个室内温度检测系统(检测室内的8个地点),因此用了Arduino+W5100+8个BS18B20温度传感器,并且把数据通过网线传到乐联网,使之能够看到实时数据。但是这个过程中存在一些没能解决的问题,希望能够得到大家的指点以解决问题。
先看例程:
/*
lewei50 open platform sensor client
This code is in the public domain.
*/
#include <LeweiClient.h>
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 //使用Digital 2端口,其它端口也可以
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature tempSensor(&oneWire);
#define LW_USERKEY "6efb239e954c493a89436279171dc62a"
#define LW_GATEWAY "01"
int temp01=0;
int temp02=0;
int temp03=0;
int temp04=0;
int temp05=0;
int temp06=0;
int temp07=0;
int temp08=0;
//delay between updates
#define POST_INTERVAL (30*1000)
//IPAddress ip(192,168,1, 15);
//IPAddress mydns(8,8,8,8);
//IPAddress gw(192,168,1,1);
//IPAddress subnet(255,255,255,0);
LeWeiClient *lwc;
void setup() {
// start serial port:
Serial.begin(9600);
// hope no exception here
tempSensor.begin();
lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY);
//lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,ip,mydns,gw,subnet);
}
void loop(void) {
// read the analog sensor:
//int sensorReading = analogRead(A0);
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (lwc) {
tempSensor.requestTemperatures(); // 发送命令获取温度
temp01=tempSensor.getTempCByIndex(1);
temp02=tempSensor.getTempCByIndex(2);
temp03=tempSensor.getTempCByIndex(3);
temp04=tempSensor.getTempCByIndex(4);
temp05=tempSensor.getTempCByIndex(5);
temp06=tempSensor.getTempCByIndex(6);
temp07=tempSensor.getTempCByIndex(7);
temp08=tempSensor.getTempCByIndex(8);
//t1,t2.. must using the same name setting on web server.
lwc->append("01",temp01);
Serial.print(";");
lwc->append("02", temp02);
Serial.print(";");
lwc->append("03", temp03);
Serial.print(";");
lwc->append("04", temp04);
Serial.print(";");
lwc->append("05", temp05);
Serial.print(";");
lwc->append("06", temp06);
Serial.print(";");
lwc->append("07", temp07);
Serial.print(";");
lwc->append("08",temp08);
Serial.println();
lwc->send();
//Grammar changed by Wei&Anonymous ;)
delay(1000);
}
}
问题一: 8个传感器的温度值都能够在乐联网显示,但是显示的值都是整数的,怎么样才能够显示两位小数的温度值呢?是不是这个例程有问题?(做其他的实验, DS18B20传感器的数据都是两位小数的)
问题二:8个DS18B20传感器在乐联网上显示的值与传感器无法一一对应,不能区分哪一个值是哪一个传感器的,这个问题怎么解决呢??
问题三:窗口为什么是这样显示的? |