bool gatewayTransportInit() {
	_w5100_spi_en(true);
	#if defined(MY_GATEWAY_ESP8266)
		#if defined(MY_ESP8266_SSID)
			// Turn off access point
			WiFi.mode (WIFI_STA);
			#if defined(MY_ESP8266_HOSTNAME)
				WiFi.hostname(MY_ESP8266_HOSTNAME);
			#endif
			(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD);
			#ifdef MY_IP_ADDRESS
				WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
			#endif
			while (WiFi.status() != WL_CONNECTED)
			{
				delay(500);
				MY_SERIALDEVICE.print(".");
				yield();
			}
			MY_SERIALDEVICE.print(F("IP: "));
			MY_SERIALDEVICE.println(WiFi.localIP());
		#endif

	#else
		#ifdef MY_IP_ADDRESS
			Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP);
		#else
			// Get IP address from DHCP
			if (!Ethernet.begin(_ethernetGatewayMAC)) {
				MY_SERIALDEVICE.print("DHCP FAILURE...");
				_w5100_spi_en(false);
				return false;
			}
		#endif 
		MY_SERIALDEVICE.print(F("IP: "));
		MY_SERIALDEVICE.println(Ethernet.localIP());
		// give the Ethernet interface a second to initialize
		delay(1000);
	#endif

	#ifdef MY_USE_UDP
		_ethernetServer.begin(_ethernetGatewayPort);
	#else
		// we have to use pointers due to the constructor of EthernetServer
		_ethernetServer.begin();
	#endif /* USE_UDP */
	_w5100_spi_en(false);
	return true;
}
示例#2
0
SNMP_API_STAT_CODES SNMPClass::begin(const char *getCommName, const char *setCommName, const char *trapCommName, uint16_t port)
{
  //initialize request counter
    requestCounter = 1;
    _extra_data_size = 0;
    _udp_extra_data_packet = false;
    
  // set community name set/get sizes
  _setSize = strlen(setCommName);
  _getSize = strlen(getCommName);
  _trapSize = strlen(trapCommName);
  //
  // validate get/set community name sizes
  if ( _setSize > SNMP_MAX_NAME_LEN + 1 || _getSize > SNMP_MAX_NAME_LEN + 1 || _trapSize > SNMP_MAX_NAME_LEN + 1) {
    return SNMP_API_STAT_NAME_TOO_BIG;
  }
  //
  // set community names
  _getCommName = getCommName;
  _setCommName = setCommName;
  _trapCommName = trapCommName;
  
  // validate session port number
  if ( port == NULL || port == 0 ) port = SNMP_DEFAULT_PORT;
  //
  // init UDP socket
  Udp.stop();
  Udp.begin(port);

  return SNMP_API_STAT_SUCCESS;
}
示例#3
0
void SyncTime_setup() 
{
  Udp.begin(LOCALPORT);
  setSyncProvider(getNtpTime);
  while(timeStatus()== timeNotSet)   
     ; // wait until the time is set by the sync provider
}
示例#4
0
/*
 * Initialize our ntp client. 
 * 
 * We need ntp time in order to have a valid, up-to-date time
 * in order to create timestamps for the data we collect.  If we dont have
 * valid time, then there's no use returning since we cant collect data
 * without valid time. 
 *
 * Note, however, that now() will still keep track of time - it will just
 * be relative to when we booted.
 */
void initNtpTime() {

	Udp.begin(8888);

	setSyncProvider(0);  // We will take care of synching time ourselves,
					   // so tell time library there's no external time source

	sendTimeRequest();	// send an initial time request to kickstart things
	
	// Wait until our request is completed.  Note that this is initialization,
	// so if we dont have a good time value, we cant collect data because
	// we wont be able to create valid timestamps.
	int retryCount = 500;
	while (ntpState == WAITING_FOR_RESPONSE) {
		delay(500);
		serviceNtpTime();
		if (--retryCount <=0) {
			// We've been trying for a while to get the time.  Let's try
			// restarting in case the network didnt come up right last time.
			retryCount = 500;
			startEthernet();  // Let's try restarting the ethernet
			restartNtpTime();
		}
	}

	if (bootTime == 0) {
	bootTime = now();
	}

  
}
void setup_ntp(){
  // setup NTP sync service
  Udp.begin(ntp_port);
  Serial.println(F("Waiting for NTP sync"));
  setSyncInterval(600); // initial one 10 minutes to take care of most of the drift
  setSyncProvider(getNtpTime);
}
void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(10,OUTPUT);
}
示例#7
0
void setup()
{
  Serial.begin(9600);
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

  Timer1.initialize(TIMER_PERIOD);
  Timer1.attachInterrupt(TimerLoop);
  Timer1.stop();
}
示例#8
0
bool SetupUdpClient ( void )
{
    bool success = false;

#ifdef INTERFACE_ETHERNET
#ifdef ETHERNET_UDPCLIENT
    success = (bool)Udp.begin(localPort);
#endif //ETHERNET_UDPCLIENT
#endif // INTERFACE_ETHERNET

    return success;
}
示例#9
0
/*
 * Restart our ntp handler.  This is only done as part of restarting the
 * network.  As such, all we want to do is make sure udp is still working.
 * We dont need to issue a time request unless one was already outstanding
 * (not likely)
 */
void restartNtpTime() {

	Udp.stop();

	Udp.begin(8888);

	// If we were already waiting for a response, let's re-issue the request
	if (ntpState == WAITING_FOR_RESPONSE) {
		sendTimeRequest();
	}

}
void UdpController::Setup()
{
    if (Ethernet.begin(MacAddress) == 0)
    {
        _traffic->ShowError();
        for(;;);
    }

    Udp.begin(Port);

    _traffic->ShowInconclusive();
    _lastUpdateMillis = millis();
}
示例#11
0
void udpService( )
{
  static DhcpState prevState = DhcpStateNone;
  
  // poll() queries the DHCP library for its current state (all possible values
  // are shown in the switch statement below). This way, you can find out if a
  // lease has been obtained or is in the process of being renewed, without
  // blocking your sketch. Therefore, you could display an error message or
  // something if a lease cannot be obtained within reasonable time.
  // Also, poll() will actually run the DHCP module, just like maintain(), so
  // you should call either of these two methods at least once within your
  // loop() section, or you risk losing your DHCP lease when it expires!
  DhcpState state = EthernetDHCP.poll();

  if (prevState != state) {

    switch (state) {
      case DhcpStateDiscovering:
        p("DHCP Discover\n");
        break;
      case DhcpStateRequesting:
        Serial.print("DHCP Request\n");
        break;
      case DhcpStateRenewing:
        Serial.print("DHCP Renew\n");
        break;
      case DhcpStateLeased: {
        Serial.println("DHCP Obtained\n");

        // Since we're here, it means that we now have a DHCP lease, so we
        // print out some information.
        const byte* ipAddr = EthernetDHCP.ipAddress();
        const byte* gatewayAddr = EthernetDHCP.gatewayIpAddress();
        const byte* dnsAddr = EthernetDHCP.dnsIpAddress();

        p(" IP address: %s\n", ip_to_str(ipAddr));
        p("    Gateway: %s\n", ip_to_str(gatewayAddr));
        p("        DNS: %s\n", ip_to_str(dnsAddr));

        if ( ! active ) {
          p("Starting NTP handler on port %u\n", localPort ) ;
          Udp.begin(localPort);
          active = true;
        }
        break;
      }
    }
    prevState = state;
  }
}
示例#12
0
SNMP_API_STAT_CODES AgentuinoClass::begin() {
    // set community names
    _getCommName = "public";
    _setCommName = "private";
    //
    // set community name set/get sizes
    _setSize = strlen(_setCommName);
    _getSize = strlen(_getCommName);
    //
    // init UDP socket
    Udp.begin(SNMP_DEFAULT_PORT);
    //
    return SNMP_API_STAT_SUCCESS;
}
示例#13
0
// Overload RobotOpenClass::begin to accept an IP address (FWA August 2012)
void RobotOpenClass::begin(uint8_t *local_ip) {
    // Setup the initial pointers to the arrays
    _packetBufferAccessor = _packetBuffer;
    _validPacketAccessor = _validPacket;
	_pwmSerialData[0] = 0xFF;
	_pwmSerialData[1] = 0x00;
	_relaySerialData[0] = 0xFF;
	_relaySerialData[1] = 0x00;
	for (int i = 2; i <= 11; i++) {
		_pwmSerialData[i] = 127;
		_relaySerialData[i] = 0;
	}
    // Start Ethernet, UDP, and Serial
    Ethernet.begin(mac,local_ip);
    Udp.begin(PORT);
    Serial.begin(115200);	// This is used to talk to the coprocessor on the RobotOpen shield
}
unsigned long getNtpTime()
{
	// We need to call the begin to reset the socket.
	// Because localClient.connect() may occupy the same socket.
	EthernetUDP theUDP;
	theUDP.begin(localPort);

	Serial.println("Sending time sync request to NTP server.");
	sendNTPpacket(timeServer); // send an NTP packet to a time server

	unsigned long startMillis = millis();
	int tryCounter = 1;
	while( millis() - startMillis < 1000)  // wait up to one second for the response
	{  // wait to see if a reply is available
		if ( theUDP.available() )
		{
			theUDP.readPacket(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer

			//the timestamp starts at byte 40 of the received packet and is four bytes,
			// or two words, long. First, esxtract the two words:
			unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
			unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
			// combine the four bytes (two words) into a long integer
			// this is NTP time (seconds since Jan 1 1900):
			unsigned long secsSince1900 = highWord << 16 | lowWord;
			// now convert NTP time into Arduino Time format:
			// Time starts on Jan 1 1970. In seconds, that's 2208988800:
			const unsigned long seventyYears = 2208988800UL;
			// subtract seventy years:
			unsigned long epoch = secsSince1900 - seventyYears;

			Serial.println("Time sync successfully.");

			return epoch;
		}

		Serial.print("No date data available. Try counter: .");
		Serial.println(tryCounter++);
		delay(100);
	}

	Serial.println("Time sync failed.");

	return 0;   // return 0 if unable to get the time
}
示例#15
0
void setup() {

    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    ADC_init();
    timer0_init();
    debug_init(PC3);
    debug_init(PC4);
    // Initialize the buffer with a capacity for 256 bytes
    charBuffer.init(256);
    // start the Ethernet connection and the server:
    Ethernet.begin(mac, serverIP);
    Udp.begin(serverPort);

    Serial.println("arduino server is at ");
    Serial.println(Ethernet.localIP());

}
示例#16
0
void hardwareInit()
{
	wdt_enable(WDTO_2S);

	// enable internal pull-ups
	digitalWrite(pinButtonSwitch, HIGH);
	digitalWrite(pinReedSwitch, HIGH);

	pinMode(pinLed, OUTPUT);
	digitalWrite(pinLed, LOW);

	uint8_t macTmp[6];
	memcpy(macTmp, mac, 6);
	Ethernet.begin(macTmp, ip);
	udp.begin(10000);

	// delaying in order to properly boot the device
	// we really need this time (about 7-10 secs)
	bootDelay();
}
示例#17
0
SNMP_API_STAT_CODES AgentuinoClass::begin(char *getCommName, char *setCommName, uint16_t port) {
    // set community name set/get sizes
    _setSize = strlen(setCommName);
    _getSize = strlen(getCommName);
    //
    // validate get/set community name sizes
    if (_setSize > SNMP_MAX_NAME_LEN + 1 || _getSize > SNMP_MAX_NAME_LEN + 1) {
        return SNMP_API_STAT_NAME_TOO_BIG;
    }
    //
    // set community names
    _getCommName = getCommName;
    _setCommName = setCommName;
    //
    // validate session port number
    if (port == NULL || port == 0) port = SNMP_DEFAULT_PORT;
    //
    // init UDP socket
    Udp.begin(port);

    return SNMP_API_STAT_SUCCESS;
}
示例#18
0
roveEthernet_Error roveEthernet_UdpSocketListen(uint16_t port)
{
  udpReceiver.begin(port);
  return ROVE_ETHERNET_ERROR_SUCCESS;
}
示例#19
0
void SyslogClass::setLoghost(uint8_t * server_ip) {
    ip_syslogserver = server_ip;
    SyslogUdp.begin(8888);
}
void commandInterfaceInit() {
  cmdsock.begin(62001);
}
示例#21
0
void setup(void)
{
	status.reset();

	/// Discrete & Analog IO
	pinMode(13, OUTPUT);	// Arduino on-board LED
	pinMode(A0, OUTPUT);	// Buzzer

	/// Comm. Channels
	// UART
	Serial.begin(115200); 	Serial.flush();
	Serial.println("Starting up greenOmatic Duemilanove Testbed...");
	Serial.print("Program compiled on ");
	Serial.print(__DATE__);
	Serial.print(" at ");
	Serial.println(__TIME__);
	Serial.println();

	// RF
#ifdef INTERFACE_ASK_RX
	pinMode(RF_RX_PIN, INPUT);
	vw_set_rx_pin(RF_RX_PIN);
    vw_setup(RF_BAUD);
    vw_rx_start  ();
	Serial.print  ("ASK RF Receiver configured on PIN ");
	Serial.print  (RF_RX_PIN);
	Serial.print  (" @ ");
	Serial.print  (RF_BAUD, DEC);
	Serial.println(" baud.");
#endif //INTERFACE_ASK_RX

	// Ethernet
#ifdef INTERFACE_ETHERNET
	Serial.print("Starting Ethernet... ");

#ifdef ETHERNET_DYNAMIC_IP
	int eth_stat = Ethernet.begin(mac);
	if (0 == eth_stat)
	{
		Serial.println(" Problem starting ethernet !");
		status.ethernet_valid = status.ERROR;
	}
	else
	{
		Serial.print("Ethernet started, IP = ");
		Serial.println( Ethernet.localIP() );
		status.ethernet_valid = status.VALID;
	}
#else
	Ethernet.begin(mac, IPaddr);
	Serial.print("Ethernet started, IP = ");
	Serial.println( Ethernet.localIP() );
	status.ethernet_valid = status.VALID;
#endif //ETHERNET_DYNAMIC_IP

#ifdef ETHERNET_WEBSERVER
		server.begin();
#endif //ETHERNET_WEBSERVER

#ifdef ETHERNET_UDPCLIENT
		Udp.begin(localPort);
#endif //ETHERNET_UDPCLIENT

#endif

	/// Peripherals
	// I2C RTC
#ifdef PERIPHERAL_RTCC
	Wire.begin();
	rtc.begin();
	if (rtc.isrunning())
	{
		status.time_valid = status.VALID;
		GetDatetimeString(rtc.now());
	    Serial.print("RTCC configured on I2C.  Time is currently ");
	    Serial.println(currentTime);

#ifdef ETHERNET_UDPCLIENT
		//TODO: Get NTP Time
#else
	    // Compare RTC time to this programs compile time
	    DateTime rtcTime = rtc.now();
	    DateTime compileTime(F(__DATE__), F(__TIME__));

	    // If the compile-time is later (more recent) than the current RTC time, update the RTC
	    if (compileTime.secondstime() > rtcTime.secondstime())
	    {
	    	Serial.println("Program compile-time is later than RTC time; updating RTC.");
	    	rtc.adjust( DateTime(F(__DATE__), F(__TIME__)) );
	    }
#endif //ETHERNET_UDPCLIENT
	}
	else
	{
		status.time_valid = status.ERROR;
		// TODO, can we narrow this down further like with the DS1307RTC library?
	}
#endif

	Serial.println("\nInitialization complete!\n\n");
}
示例#22
0
// --------------------------------------------------- Initialize UDP ------------------------------------------------------------
void init_UDP()
{
	Ethernet.begin(mac, ip);
	Udp.begin(localPort);
}