Jak*_*zuk 6 c ethernet arduino http-post request
我刚刚在Ebay上购买了新的ENC28J60以太网LAN网络模块,我想将此模块的POST数据发送到指定的网址,例如.www.mydomain.com/example.php
我重新阅读了谷歌的一些例子,但我能看到的只是arduino盾牌的例子,而不是我的模块.有了这个模块,我正在使用以下库:
"etherShield.h"
"ETHER_28J60.h"
我想将一个/两个指定的POSTS(变量)发送到php公式,但我不知道如何做到这一点.
首先,您需要安装以下库:https: //github.com/jcw/ethercard
用6个引脚将模块连接到arduino:
然后使用以下代码:
#include <EtherCard.h>
// your variable
#define PATH "example.php"
#define VARIABLE "test"
// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
char website[] PROGMEM = "www.mydomain.com";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 10000;
byte sd = stash.create();
stash.print("variable=");
stash.print(VARIABLE);
stash.print("&action=Submit");
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"
Stash::prepare(PSTR("POST http://$F/$F.csv HTTP/1.0" "\r\n"
"Host: $F" "\r\n"
"Content-Length: $D" "\r\n"
"Content-Type: application/x-www-form-urlencoded" "\r\n"
"\r\n"
"$H"),
website, PSTR(PATH), website, stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22093 次 |
| 最近记录: |