Hi all,
I recently bought 2 arduino nanos and 2 ethernet shields for them. The ethernet shield needs to use ethercard.h library. I am trying to post to my local emoncms with this library and there is no way.
I have tried multiple sketches and googling a lot with no result.
I have this sketch that is posting well to emoncms.org, but don’t work with my emoncms local. Please,can you help me?
/*
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;
const char website[] PROGMEM = "192.168.1.30";
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("/emoncms/input/post?apikey=xxxxxxxx&json="), "{power:252.4,temperature:15.4}", website, 0);
}
}