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


C++ WiFiUDP类代码示例

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


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

示例1: stopAll

void WiFiUDP::stopAll()
{
    for (WiFiUDP* it = _s_first; it; it = it->_next) {
        DEBUGV("%s %p %p\n", __func__, it, _s_first);
        it->stop();
    }
}
开发者ID:dzilarsy96,项目名称:Arduino,代码行数:7,代码来源:WiFiUdp.cpp

示例2: stopAll

void WiFiUDP::stopAll()
{
    for (WiFiUDP* it = _s_first; it; it = it->_next) {
        DEBUGV("%s %08x %08x\n", __func__, (uint32_t) it, (uint32_t) _s_first);
        it->stop();
    }
}
开发者ID:Danonesl,项目名称:Arduino,代码行数:7,代码来源:WiFiUdp.cpp

示例3: stopAllExcept

void WiFiUDP::stopAllExcept(WiFiUDP * exC) {
    for (WiFiUDP* it = _s_first; it; it = it->_next) {
        if (it->_ctx != exC->_ctx) {
            DEBUGV("%s %p %p\n", __func__, it, _s_first);
            it->stop();
        }
    }
}
开发者ID:dzilarsy96,项目名称:Arduino,代码行数:8,代码来源:WiFiUdp.cpp

示例4: stopAllExcept

void WiFiUDP::stopAllExcept(WiFiUDP * exC) {
    for (WiFiUDP* it = _s_first; it; it = it->_next) {
        if (it->_ctx != exC->_ctx) {
            DEBUGV("%s %08x %08x\n", __func__, (uint32_t) it, (uint32_t) _s_first);
            it->stop();
        }
    }
}
开发者ID:Danonesl,项目名称:Arduino,代码行数:8,代码来源:WiFiUdp.cpp

示例5: discoverSonos

int SonosEsp::discoverSonos(){
    _numberOfDevices=0;
    WiFiUDP Udp;
    Udp.begin(1900);
    IPAddress sonosIP;
    bool timedOut = false;
    unsigned long timeLimit = 15000;
    unsigned long firstSearch = millis();
    do {
        Serial.println("Sending M-SEARCH multicast");
        Udp.beginPacketMulticast(IPAddress(239, 255, 255, 250), 1900, WiFi.localIP());
        Udp.write("M-SEARCH * HTTP/1.1\r\n"
        "HOST: 239.255.255.250:1900\r\n"
        "MAN: \"ssdp:discover\"\r\n"
        "MX: 1\r\n"
        "ST: urn:schemas-upnp-org:device:ZonePlayer:1\r\n");
        Udp.endPacket();
        unsigned long lastSearch = millis();

        while((millis() - lastSearch) < 5000){
            int packetSize = Udp.parsePacket();
            if(packetSize){
                char packetBuffer[255];
                //Serial.print("Received packet of size ");
                //Serial.println(packetSize);
                //Serial.print("From ");
                sonosIP = Udp.remoteIP();

                //xxx if new IP, it should be put in an array

                addIp(sonosIP);
                //found = true; 
                Serial.print(sonosIP);
                Serial.print(", port ");
                Serial.println(Udp.remotePort());
                
                // read the packet into packetBufffer
                int len = Udp.read(packetBuffer, 255);
                if (len > 0) {
                    packetBuffer[len] = 0;
                }
                //Serial.println("Contents:");
                //Serial.println(packetBuffer);
            }
            delay(50);
        }
    } while((millis()-firstSearch)<timeLimit);
    //if (!found) {
      //sonosIP.fromString("0.0.0.0"); xxx 
    //}
    return _numberOfDevices;
}
开发者ID:bopeterson,项目名称:sonos-esp,代码行数:52,代码来源:SonosEsp.cpp

示例6: AJ_Net_RecvFrom

AJ_Status AJ_Net_RecvFrom(AJ_IOBuffer* buf, uint32_t len, uint32_t timeout)
{
    AJ_InfoPrintf(("AJ_Net_RecvFrom(buf=0x%p, len=%d., timeout=%d.)\n", buf, len, timeout));

    AJ_Status status = AJ_OK;
    int ret;
    uint32_t rx = AJ_IO_BUF_SPACE(buf);
    unsigned long Recv_lastCall = millis();

    AJ_InfoPrintf(("AJ_Net_RecvFrom(): len %d, rx %d, timeout %d\n", len, rx, timeout));

    rx = min(rx, len);

    while ((g_clientUDP.parsePacket() == 0) && (millis() - Recv_lastCall < timeout)) {
        delay(10); // wait for data or timeout
    }

    AJ_InfoPrintf(("AJ_Net_RecvFrom(): millis %d, Last_call %d, timeout %d, Avail %d\n", millis(), Recv_lastCall, timeout, g_clientUDP.available()));
    ret = g_clientUDP.read(buf->writePtr, rx);
    AJ_InfoPrintf(("AJ_Net_RecvFrom(): read() returns %d, rx %d\n", ret, rx));

    if (ret == -1) {
        AJ_InfoPrintf(("AJ_Net_RecvFrom(): read() fails. status=AJ_ERR_READ\n"));
        status = AJ_ERR_READ;
    } else {
        if (ret != -1) {
            AJ_DumpBytes("AJ_Net_RecvFrom", buf->writePtr, ret);
        }
        buf->writePtr += ret;
        AJ_InfoPrintf(("AJ_Net_RecvFrom(): status=AJ_OK\n"));
        status = AJ_OK;
    }
    AJ_InfoPrintf(("AJ_Net_RecvFrom(): status=%s\n", AJ_StatusText(status)));
    return status;
}
开发者ID:durake,项目名称:core-ajtcl,代码行数:35,代码来源:aj_net.c

示例7: getNTPTimestamp

unsigned long getNTPTimestamp()
{
  unsigned long ulSecs2000;
  
  udp.begin(ntpPort);
  sendNTPpacket(timeServer); // send an NTP packet to a time server
  delay(1000);    // wait to see if a reply is available
  int cb = udp.parsePacket();

  if(!cb)
  {
    Serial.println("Timeserver not accessible! - No RTC support!"); 
    ulSecs2000=0;
  }
  else
  {
    Serial.print("packet received, length=");
    Serial.println(cb);
    udp.read(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):
    ulSecs2000  = highWord << 16 | lowWord;
    ulSecs2000 -= 2208988800UL; // go from 1900 to 1970
    ulSecs2000 -= 946684800UL; // go from 1970 to 2000
  }    
  return(ulSecs2000);
}
开发者ID:JhonControl,项目名称:ESP8266-DS18B20-Google-Chart,代码行数:33,代码来源:time_ntp.cpp

示例8: getNtpTime

time_t getNtpTime() {
  while (Udp.parsePacket() > 0)
    ; // discard any previously received packets
  //Serial.println("$CLS,Y0,X0#TX NTP RQ");
  PulseLed(BLUE, 2, 50, 10);
  sendNTPpacket(timeServer);
  uint32_t beginWait = millis();
  uint32_t waited = millis() - beginWait;
  while (waited < 3000)
  {
    int size = Udp.parsePacket();
    if (size >= NTP_PACKET_SIZE) {
      //Serial.println("$CLS,Y0,X0#RX NTP OK");
      Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 = (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      analogWrite(GREEN, 100);
      analogWrite(RED, 0);
      analogWrite(BLUE, 0);
      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR + (waited / 1000);
    }
    waited = millis() - beginWait;
  }
  //Serial.println("$CLS,Y0,X0#*** NTP TO ***");
  PulseLed(RED, 4, 50, 10);
  analogWrite(GREEN, 0);
  analogWrite(RED, 100);
  analogWrite(BLUE, 0);
  return 0; // return 0 if unable to get the time
}
开发者ID:RitterRBC,项目名称:Arduino,代码行数:34,代码来源:NTP_I2C_Witty.cpp

示例9: AJ_Net_MCastUp

AJ_Status AJ_Net_MCastUp(AJ_MCastSocket* mcastSock)
{
    uint8_t ret = 0;

    AJ_InfoPrintf(("AJ_Net_MCastUp(mcastSock=0x%p)\n", mcastSock));

    //
    // Arduino does not choose an ephemeral port if we enter 0 -- it happily
    // uses 0 and then increments each time we bind, up through the well-known
    // system ports.
    //
    ret = g_clientUDP.begin(AJ_EphemeralPort());

    if (ret != 1) {
        g_clientUDP.stop();
        AJ_ErrPrintf(("AJ_Net_MCastUp(): begin() fails. status=AJ_ERR_READ\n"));
        return AJ_ERR_READ;
    } else {
        AJ_IOBufInit(&mcastSock->rx, rxData, sizeof(rxData), AJ_IO_BUF_RX, (void*)&g_clientUDP);
        mcastSock->rx.recv = AJ_Net_RecvFrom;
        AJ_IOBufInit(&mcastSock->tx, txData, sizeof(txData), AJ_IO_BUF_TX, (void*)&g_clientUDP);
        mcastSock->tx.send = AJ_Net_SendTo;
    }

    AJ_InfoPrintf(("AJ_Net_MCastUp(): status=AJ_OK\n"));
    return AJ_OK;
}
开发者ID:durake,项目名称:core-ajtcl,代码行数:27,代码来源:aj_net.c

示例10: radioTransceiverTask

void radioTransceiverTask(const void *arg) {

	unsigned long tv;
	static unsigned long  radio_last_tv2 = 0;
	while (true){

#if 1
#if 0 //debug
		tv=millis();
		 Serial.println(tv-radio_last_tv2);
		 radio_last_tv2=tv;
#endif

			memset(transceiverBuffer, '\0', sizeof(transceiverBuffer));
			sprintf(transceiverBuffer,
						"@%3.2f:%3.2f:%3.2f:%3.2f:%3.2f:%3.2f:%3.2f:%3.2f:%3.2f:%d:%d:%d:%d:%d#",
						getRoll(), getPitch(), getYaw(), getPidSp(&rollAttitudePidSettings),
						getPidSp(&pitchAttitudePidSettings),  getYawCenterPoint() + getPidSp(&yawAttitudePidSettings),
						getRollGyro(), getPitchGyro(), getYawGyro(),
						getThrottlePowerLevel(), getMotorPowerLevelCCW1(),
						getMotorPowerLevelCW1(), getMotorPowerLevelCCW2(),
						getMotorPowerLevelCW2());
	
				Udp.beginPacket(broadcastIP, localPort);
				Udp.write(transceiverBuffer,strlen(transceiverBuffer));
				Udp.endPacket();
				
			increasePacketAccCounter();
	    os_thread_yield();
		delay(TRANSMIT_TIMER);
#endif
		}

}
开发者ID:Ameba8195,项目名称:Arduino,代码行数:34,代码来源:radio_control.cpp

示例11: setup

void setup() {

  Serial.begin(115200);
  Serial.println("Booting");
  Serial.println(ESP.getResetInfo());
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  Serial.println("Starting UDP");
  udp.begin(localPort);
  Serial.print("Local port: ");
  Serial.println(udp.localPort());


  // -- OTA
    // OTA options
    // Port defaults to 8266
    // ArduinoOTA.setPort(8266);
    // Hostname defaults to esp8266-[ChipID]
    // ArduinoOTA.setHostname("myesp8266");
    // No authentication by default
    // ArduinoOTA.setPassword((const char *)"123");

    ArduinoOTA.onStart([]() {
      Serial.println("Start");
    });
    ArduinoOTA.onEnd([]() {
      Serial.println("\nEnd");
    });
    ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    });
    ArduinoOTA.onError([](ota_error_t error) {
      Serial.printf("Error[%u]: ", error);
      if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
      else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
      else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
      else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
      else if (error == OTA_END_ERROR) Serial.println("End Failed");
    });
    ArduinoOTA.begin();

  Serial.println("Ready");
  Serial.print("IP address: ");
  local_ip_str = WiFi.localIP().toString();
  Serial.println(local_ip_str);

  // neopixel bus
  strip.Begin();
  strip.Show();

}
开发者ID:jakeloggins,项目名称:Clod-sketch-library,代码行数:57,代码来源:main.cpp

示例12: send

void Protocol::send(const char* message)
{
  #ifdef MODULE_CAN_DEBUG
  Serial.print("Send message: ");
  Serial.println(message);
  #endif

  Udp.beginPacket(_ip, _port);
  Udp.write(message);
  Udp.endPacket();
}
开发者ID:renanvaz,项目名称:arduino-mqtt-api,代码行数:11,代码来源:UDP.cpp

示例13: setupTime

void setupTime()
{
  print_dbg("IP number assigned by DHCP is ");
  println_dbg(WiFi.localIP());
  println_dbg("Starting UDP");
  Udp.begin(localPort);
  print_dbg("Local port: ");
  println_dbg(Udp.localPort());
  println_dbg("waiting for sync");
  setSyncProvider(getNtpTime);
}
开发者ID:kerikun11,项目名称:Light-for-Fish,代码行数:11,代码来源:time_op.cpp

示例14: at_send_udp_packet

void at_send_udp_packet(const char *format, ...)
{
  /* Construct databuffer to send */
  char mybuffer[AT_UDP_MAX_LENGTH];
  va_list myargs;
  va_start (myargs, format);
  vsnprintf(mybuffer, AT_UDP_MAX_LENGTH, format, myargs);
  va_end(myargs);
  //Serial.println(mybuffer);
  at_udp.beginPacket(drone_ip, AT_UDP_PORT);
  at_udp.print(mybuffer);
  at_udp.endPacket();
}
开发者ID:TXBOXY,项目名称:TXBoxy-PT,代码行数:13,代码来源:at_commands.cpp

示例15: CAIPSendData

void CAIPSendData(CAEndpoint_t *endpoint,
                  const void *data, uint32_t dataLength, bool isMulticast)
{
    OIC_LOG(DEBUG, TAG, "IN");

    VERIFY_NON_NULL_VOID(data, TAG, "data");
    VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint");

    OIC_LOG_V(DEBUG, TAG, "remoteip: %s", endpoint->addr);
    OIC_LOG_V(DEBUG, TAG, "port: %d", endpoint->port);

    uint8_t ip[4] = {0};
    uint16_t parsedPort = 0;
    CAResult_t res = CAParseIPv4AddressInternal(endpoint->addr, ip, sizeof(ip),
                     &parsedPort);
    if (res != CA_STATUS_OK)
    {
        OIC_LOG_V(ERROR, TAG, "Remote adrs parse fail %d", res);
        return;
    }

    IPAddress remoteIp(ip);
    Udp.beginPacket(remoteIp, endpoint->port);

    uint32_t bytesWritten = 0;
    while (bytesWritten < dataLength)
    {
        // get remaining bytes
        size_t writeCount = dataLength - bytesWritten;
        // write upto max ARDUINO_WIFI_BUFFERSIZE bytes
        writeCount = Udp.write((uint8_t *)data + bytesWritten,
                               (writeCount > ARDUINO_IP_BUFFERSIZE ?
                                ARDUINO_IP_BUFFERSIZE:writeCount));
        if(writeCount == 0)
        {
            // write failed
            OIC_LOG_V(ERROR, TAG, "Failed after %u", bytesWritten);
            break;
        }
        bytesWritten += writeCount;
    }

    if (Udp.endPacket() == 0)
    {
        OIC_LOG(ERROR, TAG, "Failed to send");
        return;
    }
    OIC_LOG(DEBUG, TAG, "OUT");
    return;
}
开发者ID:chetan336,项目名称:iotivity,代码行数:50,代码来源:caipclient_wifi.cpp


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