|
本帖最后由 kevinzhang19701 于 2014-2-18 20:58 编辑
没有做过Java的东西,那做这个会有点难度。
程序代码我稍微改了一下。
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192,168,11,101); // server ip address
IPAddress ip(192,168,11,99); // w5100 ip address
EthernetClient client;
float exchange(float val)
{
float ppm;
if(val>=325)
{
ppm=400;
delay(100);
}
else if((val<325)&&(val>=315))
{
ppm=pow(10,(455.78-val)/50.26);
delay(100);
}
else if((val<315)&&(val>=265))
{
ppm=pow(10,(425.00-val)/40.00);
delay(100);
}
else if(val<265)
{
ppm=10000;
delay(100);
}
return(ppm);
delay(100);
} //CO2传感器的输出电压值到浓度值的转换函数
void setup()
{
int val,i,sum=0,mean=0;
float VAL,ppm,q;
int analogChannel = 0;
for(i=0;i<10;i++)
{
sum+= analogRead(analogChannel);
delay(100);
}
mean=sum/10;
VAL = ((5.0*mean)/1023-0.03)/3;
ppm = exchange(1000*VAL); //CO2传感器的相关参数的采集和计算
Ethernet.begin(mac,ip);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
if (client.connect(server, 3333))
{
Serial.println("connected");
client.println("GET http://192.168.11.101/servlet/unotest?q=" + ppm + " HTTP/1.0");
client.println("Host: 192.168.11.101");
client.println();
}
else
{
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available())
{
client.print(ppm);
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}
|
|