Project

General

Profile

EtherCard with NTP and then accessing another site?

Added by greg over 5 years ago

I’ve managed to find some example code and got NTP requests working with the EtherCard.

https://github.com/thiseldo/EtherCardExamples/blob/master/EtherCard\_ntp/EtherCard\_ntp.ino

I also managed to get another project going which sends data to ThingSpeak

The thing is now when I try and combine both programs the ethernet stops working. Im pretty convinced its because I initialize the card and setup api.thingspeak.com - call the routine which sends data to thingspeak, and then every 15 mins call the ntp routine which fetches data from a time server which causes problems.

N00b alert……..Some advice….what would be the best way to use EtherCard to address multiple sites. Do I need to do something like a ether.close (I know that doesn’t exist) before I get it to address another server?

Should I have multiple variables, one set for ntp and another for thingspeak, so something like:

byte Ethernet::buffer_api[BUFFER_SIZE];
byte Ethernet::buffer_ntp[BUFFER_SIZE];

Then in the setup could I initialize the ethercard twice?
ether.begin(sizeof Ethernet::buffer_api, mymac);
ether.begin(sizeof Ethernet::buffer_ntp, mymac);

I’m not looking for the code to do this, just the right method of going to siteA, and then going to SiteB

Thanks


Replies (1)

RE: EtherCard with NTP and then accessing another site? - Added by teding over 5 years ago

I’Am doing what you want to do,
How ?
I left the NTP example as it is.

uint8_t webip[4];   //ip adress van exosite.com server
char website[] PROGMEM = "m2.exosite.com" ; 

in my setup I make a copy of the (exosite.com) IP

  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
  ether.copyIp(webip,ether.hisip) ;
  ether.printIp("web: ",webip);

At interval I send the data to the website,
first I recopy the webip back to ether.hisip

  if ((Min.check() == 1)) { 
    ether.copyIp(ether.hisip,webip) ;
    byte sd = stash.create();
    stash.print("Barometer=");
    stash.print((float)PayL_10.pres/100,1);  

Then after stash::prepare

    session = ether.tcpSend();     // send the packet - this also releases all stash buffers once done
    freeCount = stash.freeCount();
    if (freeCount <= 3) {   Stash::initMap(56); } 

  }
  reply = ether.tcpReply(session);
  if (reply != 0){
    Serial.println(F(" >>>REPLY recieved...."));
    Serial.println(reply);
  }

The NTP example will set the IP of one of the 5 NTP servers as needed,

    (1-1/1)