当前位置: 首页>>代码示例>>C++>>正文


C++ EthernetUDP::begin方法代码示例

本文整理汇总了C++中EthernetUDP::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ EthernetUDP::begin方法的具体用法?C++ EthernetUDP::begin怎么用?C++ EthernetUDP::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EthernetUDP的用法示例。


在下文中一共展示了EthernetUDP::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: gatewayTransportInit

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;
}
开发者ID:Clio75,项目名称:MySensors,代码行数:49,代码来源:MyGatewayTransportEthernet.cpp

示例2: begin

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;
}
开发者ID:rexpark,项目名称:Arduino-SNMP,代码行数:31,代码来源:ArduinoSNMP.cpp

示例3: SyncTime_setup

void SyncTime_setup() 
{
  Udp.begin(LOCALPORT);
  setSyncProvider(getNtpTime);
  while(timeStatus()== timeNotSet)   
     ; // wait until the time is set by the sync provider
}
开发者ID:johnmckerrell,项目名称:YAHMS,代码行数:7,代码来源:YAHMS_SyncTime.cpp

示例4: initNtpTime

/*
 * 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();
	}

  
}
开发者ID:chuckhinson,项目名称:lizard,代码行数:42,代码来源:ntptime.cpp

示例5: setup_ntp

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);
}
开发者ID:Orthogonal-Systems,项目名称:amc7812,代码行数:7,代码来源:amc7812_monitoringServer_inet.cpp

示例6: setup

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);
}
开发者ID:osu-underwater,项目名称:materov2013,代码行数:9,代码来源:acknowledger.cpp

示例7: setup

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();
}
开发者ID:cytrus77,项目名称:Arduinosy,代码行数:11,代码来源:RET_Emu_NKI.cpp

示例8: SetupUdpClient

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;
}
开发者ID:mechatrocity,项目名称:greenOmatic,代码行数:12,代码来源:Ethernets.cpp

示例9: restartNtpTime

/*
 * 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();
	}

}
开发者ID:chuckhinson,项目名称:lizard,代码行数:18,代码来源:ntptime.cpp

示例10: Setup

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

    Udp.begin(Port);

    _traffic->ShowInconclusive();
    _lastUpdateMillis = millis();
}
开发者ID:matrosovalexei,项目名称:Laconic.TrafficLight,代码行数:13,代码来源:UdpController.cpp

示例11: udpService

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;
  }
}
开发者ID:phord,项目名称:master_clock,代码行数:50,代码来源:Udp.cpp

示例12: begin

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;
}
开发者ID:johnyHV,项目名称:Arduino-SNMP,代码行数:14,代码来源:Agentuino.cpp

示例13: begin

// 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
}
开发者ID:Team766,项目名称:RobotOpen2006,代码行数:18,代码来源:RobotOpen.cpp

示例14: getNtpTime

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
}
开发者ID:JeffreyZksun,项目名称:easyrobot2,代码行数:45,代码来源:PachubeWithRealTimeNoLib.cpp

示例15: setup

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());

}
开发者ID:victorsantosdev,项目名称:opencv-avr-robot,代码行数:18,代码来源:main.cpp


注:本文中的EthernetUDP::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。