DeckTone DeckTone - 2 months ago 37
C Question

Sending POST Data with Arduino and ENC28J60 Ethernet LAN Network Module

I just bought new ENC28J60 Ethernet LAN Network Module on Ebay, and I want to send POST Data with this module to specified web address eg.

I resereached google for some examples, but all I could saw were examples for arduino shield, not module I have. With this module I'm using following libraries:



I want to send one/two specified POSTS (variables) to the php formular, but i don't know how to do this.


First of all you need to install following library:

connect your module to arduino with 6 pins:

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

then use following code:

#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 = "";

byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;

void setup () {

  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 () {

  if (millis() > timer) {
    timer = millis() + 10000;

    byte sd = stash.create();

    // 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"
            website, PSTR(PATH), website, stash.size(), sd);

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