6

Ebay で新しい ENC28J60 イーサネット LAN ネットワーク モジュールを購入しました。このモジュールで POST データを指定の Web アドレスに送信したいと考えています。www.mydomain.com/example.php

いくつかの例についてグーグルを調べましたが、私が見たのは、私が持っているモジュールではなく、arduino シールドの例だけでした。このモジュールでは、次のライブラリを使用しています。

「etherShield.h」
「ETHER_28J60.h」

指定した 1 つまたは 2 つの POSTS (変数) を php フォーミュラーに送信したいのですが、その方法がわかりません。

4

5 に答える 5

6

まず、次のライブラリをインストールする必要があります: https://github.com/jcw/ethercard

モジュールを arduino に 6 ピンで接続します。

  • ENC SO -> Arduino ピン 12
  • ENC SI -> Arduino ピン 11
  • ENC SCK -> Arduino ピン 13
  • ENC CS -> Arduino ピン 8
  • ENC VCC -> Arduino 3V3 ピン
  • ENC GND -> Arduino Gnd ピン

次に、次のコードを使用します。

#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();
  }
}
于 2013-07-22T20:05:28.517 に答える
2

誰かが API を呼び出しようとしている場合は、次のように、リクエストで .csv を削除する必要があります。

 byte sd = stash.create();
    stash.print("variable="); //change this to your post 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"
//remove the .csv
Stash::prepare(PSTR("POST http://$F/$F 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);

追加情報として、テストにローカル サーバーを使用している場合は、Wampp または Xampp サーバーのアクセス ログを表示して、リクエストがサーバーに到達したかどうかを確認できます。

そして、次の行で const を使用します。

char const website[] PROGMEM = "www.mydomain.com";
于 2018-10-17T07:09:04.113 に答える
1

標準の Ethernet-lib と完全に互換性のある次のライブラリを試してみてください。

https://github.com/ntruchsess/arduino_uip

このライブラリを [arduino-dir]/libraries/UIPEthernet にインストールすると、Arduino-IDE イーサネットの例が機能し、標準のイーサネットの例 (例: examples->Ethernet->WebServer) を開き、インクルード "Ethenet.h" を " UIPEthernet.h".

于 2013-10-08T09:38:19.573 に答える