Petter Holt Juliussen • Mail | GitHub | Letterboxd

for later reference.

ENC28J60

2019-04-04

Connection

ENC28J60

Libraries

Sketch

#include <EtherCard.h>

static byte mymac[] = {0x74, 0x69, 0x69, 0x2D, 0x30, 0x31};
static byte myip[] = {192, 168, 1, 203};
static byte gwip[] = {192, 168, 1, 1};  
static byte maskip[] = {255, 255, 255, 0}; 
static byte dnsip[] = {192, 168, 1, 1};  
static byte hisip[] = {95, 85, 43, 82};
byte Ethernet::buffer[700];
static uint32_t timer;
const char website[] PROGMEM = "95.85.43.82";

void setup()
{
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) {
    // Failed to access Ethernet controller
  }

  ether.copyIp(ether.hisip, hisip);

  if (ether.staticSetup(myip, gwip, dnsip, maskip)) {
    delay(1000);

    ether.printIp("IP:  ", ether.myip);
    ether.printIp("GW:  ", ether.gwip); 
    ether.printIp("MSK: ", ether.netmask); 
    ether.printIp("DNS: ", ether.dnsip);
    ether.printIp("SRV: ", ether.hisip);

    while (ether.clientWaitingGw())
      ether.packetLoop(ether.packetReceive());

    // GATEWAY FOUND
  }
  else {
    // STATIC FAIL
  }
}

void loop() 
{
  ether.packetLoop(ether.packetReceive());

  if (millis() > timer) {
    timer = millis() + 30000;
    // REQUEST
    ether.browseUrl(PSTR("/api/"), "", website, response_callback);
  }
}


static void response_callback(byte status, word off, word len) {
  // RESPONSE  
  Ethernet::buffer[off+300] = 500;
  String response = Ethernet::buffer + off;
}