Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: new library UIPEthernet: uIP adapted to Arduiono for ENC28J60 on: January 18, 2014, 12:42:14 pm
Absolute excellent job. !!!!! smiley smiley smiley

I have only a problem with DNS. The sketch below works fine with the original Ethernet Lib. But with the UIPEthernet Lib I get only 0.0.0.0 for the resolved IP  smiley-confuse

Code:
#include <Dhcp.h>
#include <Dns.h>
#include <ethernet_comp.h>
#include <UIPClient.h>
#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPUdp.h>


IPAddress ip(192,168,0,215); // Test
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xB5 };  // Test

IPAddress dnsServer(212,98,37,128);
IPAddress gateway(192,168,0,2);
IPAddress subnet(255,255,255,0);

DNSClient DNS;
char ntpServer[] = "0.ch.pool.ntp.org";
IPAddress timeServer;

void setup()  {
  Serial.begin(9600);
  Serial.println("start");
 
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  DNS.begin(dnsServer);
}

void loop()  {
  Serial.print("get IP of: ");
  Serial.println(ntpServer);
  DNS.getHostByName(ntpServer,timeServer);
  Serial.println(timeServer);
  Serial.println(); 
  delay(10000);
}

By the way I had to remove the Ethernet Lib out of the Arduino libraries otherwise I get a "double definition in DNS.h
2  Using Arduino / Programming Questions / Re: Making a library for a NTP - timeserver request on: February 13, 2013, 03:01:04 pm
@makvr, SurferTim: The code or the address isn't the problem.

I aim is to put as much as possible in the library here I struggle. My code looks like this:

ntp.h:
Code:
/*
  NTP -  Libary to contact an NTP server and read the NTP signal
*/

// ensure this library description is only included once
#ifndef NTP_h
#define NTP_h

#include "Arduino.h"
#include <SPI.h>
#include <EthernetUdp.h>
#include <Dns.h>



class NTP

{
  const char ntpServer[];
  const int NTP_PACKET_SIZE;

  public:
    NTP();
    void begin();
    unsigned long NTP_server_answer();

  private:
    byte packetBuffer[ NTP_PACKET_SIZE];
    IPAddress timeServer;
    unsigned long sendNTPpacket(IPAddress& address);
};

#endif



NTP.ccp
Code:
/*
  NTP -  Libary to contact an NTP server and read the NTP signal
*/


#include "NTP.h"



// Constructor /////////////////////////////////////////////////////////////////


NTP::NTP():

  char ntpServer[]("0.ch.pool.ntp.org"),
  int NTP_PACKET_SIZE (48);
{
  DNSClient DNS;
  EthernetUDP Udp;
}

// Public Methods //////////////////////////////////////////////////////////////

void NTP::begin(IPAddress gateway)
{
  DNS.begin(gateway);
  Udp.begin(8888);
}

unsigned long NTP::NTP_server_answer() {
  unsigned long epoch = 0;
 
  DNS.getHostByName(ntpServer,timeServer);
  sendNTPpacket(timeServer); // send an NTP packet to a time server
  delay(1000); 
  if ( Udp.parsePacket() ) { 
    Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer
    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); 
    unsigned long secsSince1900 = highWord << 16 | lowWord; 
    epoch = secsSince1900 - 2208988800UL;  // Heute   
  }
  return epoch;
}


// Private Methods /////////////////////////////////////////////////////////////

unsigned long NTP::sendNTPpacket(IPAddress& address)
{
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
   packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer,NTP_PACKET_SIZE);
  Udp.endPacket();
}

and the test sketch:
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <NTP.h>



IPAddress ip(192,168,0,205); // IBoard pro
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xA5 };  // IBoard pro
IPAddress gateway(192,168,0,2);
IPAddress subnet(255,255,255,0);

NTP Zeit;

void setup() {
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  Serial.begin(9600);
  Zeit.begin();
 
  Serial.println(Zeit.NTP_server_answer());
}

void loop() {
}

3  Using Arduino / Programming Questions / Making a library for a NTP - timeserver request on: February 12, 2013, 05:01:37 pm
I would like to synchonize my board with a NTP server and use a library for this. There are some libraries in the web but they have all the same problem: They use a fixed IP and as NTP servers change regularly my project want last for long  smiley-cry

Therefore I put some code parts thogether I found on differnt places. Now I have a sketch which can resolve the DNS and works fine  smiley

Now comes my problem. I want to put this into a library and failed by far  smiley-mad smiley-mad smiley-mad. I can built simple libraries and don't require a basic instruction but when the compiler comes where I need to initialize the DNS costructor : Error Error.......

Can some one help me? Here is my sketch:
Code:
#include <SPI.h>         
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Dns.h>


DNSClient DNS;
char ntpServer[] = "0.ch.pool.ntp.org";
IPAddress timeServer;
EthernetUDP Udp;
const int NTP_PACKET_SIZE= 48;
byte packetBuffer[ NTP_PACKET_SIZE]; 

IPAddress ip(192,168,0,205);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xA5 };
IPAddress gateway(192,168,0,2);
IPAddress subnet(255,255,255,0);



void setup() {
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  Serial.begin(9600);

  DNS.begin(gateway);
  Udp.begin(8888);
 
  Serial.println(NTP_server_answer());
}

void loop() {
}


unsigned long NTP_server_answer() {
  unsigned long epoch = 0;
 
  DNS.getHostByName(ntpServer,timeServer);
  sendNTPpacket(timeServer);
  delay(1000); 
  if ( Udp.parsePacket() ) { 
    Udp.read(packetBuffer,NTP_PACKET_SIZE);
    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); 
    unsigned long secsSince1900 = highWord << 16 | lowWord; 
    epoch = secsSince1900 - 2208988800UL;   
  }
  return epoch;
}

unsigned long sendNTPpacket(IPAddress& address)
{
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  packetBuffer[0] = 0b11100011;
  packetBuffer[1] = 0;
  packetBuffer[2] = 6;
  packetBuffer[3] = 0xEC;
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;
  Udp.beginPacket(address, 123);
  Udp.write(packetBuffer,NTP_PACKET_SIZE);
  Udp.endPacket();
}

4  Topics / Home Automation and Networked Objects / Re: HELP on pushingbox HTTP request on: November 28, 2012, 04:20:34 am
Yes. devid is an array of char which contains the API - Key (I use different Pushingbox messages):

char devid[]
5  Topics / Home Automation and Networked Objects / Re: HELP on pushingbox HTTP request on: November 27, 2012, 06:22:45 pm
Yes you would be right. Often the answer on the problem is in the response. But not here as I don't get any response at all. It seams that the server doesn't simply understand anything after get connected.

I found a kind of solution which makes it working now but it isn't really a sadifying solution:

The official example is like this: (and doesn't work)
Code:
    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();


If I replace it and write everything in one line to the client it works
Code:
   
if(DEBUG){Serial.println("sendind request");}
    client.println("GET /pushingbox?devid=vXXXXXXXXXXXXXXX HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
?????
What is going wrong here??
6  Topics / Home Automation and Networked Objects / Re: HELP on pushingbox HTTP request on: November 26, 2012, 07:59:59 pm
Same issue on my side or even worse. My sketch (the GET request pretty much as the official one) worked now for about 3 month well. Now it doesn't work any more and the official one doesn't work either.

From the browser or with curl it works perfect on my PC.

What makes it really strange: My sketch places a GET request to an other server at the same time. This works as it should.
Pages: [1]