Arduino Mega 2560 + Wiznet w5100 based Arduino shield

Hi Everyone

I have searched the forums but without any success so am hoping that someone may be able to help.

I am using an Arduino Mega 2560 + Wiznet w5100 based Arduino shield and would like to covert Trystan's Basic Web Client example for use with my Wiznet w5100 controller rather than the ENC28J60 but just cant seem to convert it without lots of errors.

Any help much appreciated.

Thanks

Andrew

 

/*
  This is a basic web client demo sending test data to emoncms
  It sends a couple of example variables in a semi-json like format: {power:252.4,temperature:15.4}
 
  Try creating an account on emoncms.org then get the write api key and enter in line 51 replacing
  the text YOURAPIKEY.
 
  This example features both DCHP and DNS Lookup.
 
  DHCP is where we ask the router for an ip address.
 
  DNS is where we ask a Domain name server for the ip address of the server we want to send data to:
  the domain name emoncms.org is linked to the ip address 213.138.101.177
  Using DNS Lookup we can save having to remember these hard to remember strings of numbers.

  -----------------------------------------
  Part of the openenergymonitor.org project
  Licence: GNU GPL V3
*/

#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
unsigned long timer;

char website[] PROGMEM = "emoncms.org";

void setup ()
{
  Serial.begin(9600);
  Serial.println("03 - Basic Web Client");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
   
  // DHCP Setup
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip); 
  ether.printIp("DNS: ", ether.dnsip); 

  // DNS Setup
  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
   
  ether.printIp("SRV: ", ether.hisip);
}

void loop () {
  ether.packetLoop(ether.packetReceive());
 
  if ((millis()-timer)>5000) {
    timer = millis();
    Serial.println("Request sent");
   
    // Send some test data to the server:
    ether.browseUrl(PSTR("/api/post.json?apikey=YOURAPIKEY&json="), "{power:252.4,temperature:15.4}", website, 0);
  }
}

Robert Wall's picture

Re: Arduino Mega 2560 + Wiznet w5100 based Arduino shield

Wouldn't a better starting point be the emonBase Open-Kontrol-Gateway example on Github?

AJTaylor79's picture

Re: Arduino Mega 2560 + Wiznet w5100 based Arduino shield

Hi Robert

I took a look at that but really wanted s really simple example as a starting point and wasn't sure what the differences between the Wiznet 5100 and 5200 were and if this affected things or not.

Thanks

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.