arduino uno传输信号到服务器,使用ENC28J60 通过HTTP 传输传感器数据给服务器遇到问题~...

send_data2web(IN char *temp,IN char *hum)

{

char data2send1 = temp;

char data2send2 = hum;

String PostData="sample={"fittingId":1,";

unsigned char i;

for(i=1;i<3;i++)

{

PostData=PostData+""channel-";

PostData=String(PostData+i);

PostData=PostData+"":";

PostData=String(PostData + String(data2send+i);

if(i!=5)

PostData=PostData+",";

}

PostData=PostData+"}";

byte sd = stash.create();

stash.println(PostData);

stash.save();

// generate the header with payload - note that the stash size is used,

// and that a "stash descriptor" is passed in as argument using "$H"

// send the packet - this also releases all stash buffers once done

ether.tcpSend();

if (client.connect(website, 80))   //这个如何判断是不是连上我的服务器

{

Serial.println("\nconnected...");

Serial.println("ARDUINO: forming HTTP request message");

client.println("POST /UNIControl/PhpPost.php HTTP/1.1"); //setting PHP

client.println("From: Arduino_room1 ");

client.println("POST /tinyFittings/index.php HTTP/1.1");

client.println("Host:  192.168.2.42");

client.println("User-Agent: Arduino/1.0");

client.println("Connection: close");

client.println("User-Agent: HTTPTool/1.0");

client.println("Content-Type: application/x-www-form-urlencoded");

client.print  ("Content-Length:");

client.println(DatatoSend.length());

client.println("Connection: close");

client.println(DatatoSend);

client.println();

Serial.println("ARDUINO: HTTP message sent");

delay(3000);

if(client.available())

{

Serial.println("ARDUINO: HTTP message received");

Serial.println("ARDUINO: printing received headers and script response...\n");

while(client.available())

{

char c = client.read();

Serial.print(c);

}

}

else

{

Serial.println("ARDUINO: no response received / no response received in time");

}

client.stop();

}

else

{

Serial.println("connection failure");

}

delay(2000);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值