Arduino论坛
登录
直播中
zhlgcc
13年用户
3经验值
私信
关注
[问答]
arduino作为Web客户端如何使用http请求访问本地服务器
开启该帖子的消息推送
Arduino
想法是这样的,使用arduino测温湿度,我在本地架了一个服务器,现在想将arduino测量的温湿度传递给服务器,服务器对数据进行保存。
我用protues做了模拟,用arduino做为web服务器可以访问,在网页上控制灯的开关都没有问题。
但是,用arduino作为web客户端就不会了。
1.服务端:服务端保存数据的URL为http://localhost:8080/yundu/arduino/wd/saveFromArduino?wd=10(←只有一个参数,就是温度,变量名为wd)
我直接在浏览器中输入这个URL,可以保存到数据库。
2.现在就卡在arduono怎么使用HTTP GET请求了。也想了很多办法,找了一些库文件。
根据Ethernet自带的WebClient例子,我做了如下修改,尚未成功
(我本地服务器的ip为192.168.1.102)
我有个疑问,有劳各位解惑,是不是访问本地服务器需要配置网关呢?
#include
#include
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192,168,1,102); // 我本地服务器的IP
IPAddress ip(192,168,1,177);
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
}
// start the Ethernet connec
ti
on:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 8080)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /yundu/arduino/wd/saveFromArduino?wd=10 HTTP/1.1");//保存数据的URL
client.println("Host:192.168.1.102");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
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:
while(true);
}
}
已退回
3
积分
回帖
(4)
dylandavid
2015-12-20 18:22:21
我就看看,学习学习,抱着学习的态度。
我就看看,学习学习,抱着学习的态度。
举报
王生
2016-1-9 17:08:11
看起来还不错哈
看起来还不错哈
举报
838663302
2017-1-26 17:12:39
楼主搞定了吗,我也遇到了同样的问题,但是http请求可以访问远程服务器
楼主搞定了吗,我也遇到了同样的问题,但是http请求可以访问远程服务器
举报
838663302
2017-1-26 17:13:07
楼主解决了吗
楼主解决了吗
举报
更多回帖
rotate(-90deg);
回复
相关问答
Arduino
ESP8266
Arduino
服务器
“连接已重置”的原因?
2023-02-27
330
ESP32
Web
服务器
可以向外部Rest API发起
HTTP
请求
吗?
2023-03-01
434
如何实现ESP32上运行运行
HTTP
服务器
?
2023-03-02
393
如何将Ubuntu电脑
作为
服务器
端去使用呢
2021-12-29
1531
Arduino
核心v3.0.2的网络
服务器
有点卡住了是什么原因造成的?
2023-02-21
375
求助:labview
服务器
如何实时
访问
客户端
2018-05-14
3370
采用GR47和MCU实现无线嵌入式
Web
Server
2019-06-20
2213
使用
Arduino
编程和esp32的开发板,多个
客户端
连接
服务器
时怎么判断是哪个
客户端
发送过来的数据?
2022-05-23
2428
Arduino
IDE让网络
服务器
显示一些网页,一旦
客户端
与
Web
服务器
断开连接将停止循环是为什么?
2023-06-07
308
使用esP8266
作为
客户端
通过连接路由
器
之后
访问
别的
服务器
如何避免重新设置?
2022-01-19
1791
发帖
登录/注册
20万+
工程师都在用,
免费
PCB检查工具
无需安装、支持浏览器和手机在线查看、实时共享
查看
点击登录
登录更多精彩功能!
首页
论坛版块
小组
免费开发板试用
ebook
直播
搜索
登录
×
20
完善资料,
赚取积分