本文整理汇总了C++中WiFiClient类的典型用法代码示例。如果您正苦于以下问题:C++ WiFiClient类的具体用法?C++ WiFiClient怎么用?C++ WiFiClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WiFiClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sendMessage
int transportMgr::sendMessage(WiFiClient socket,String sendBuf)
{
char bufHeader[20];
long length=sendBuf.length();
sprintf(bufHeader,"%s%08d",PACKET_MAGIC,length);
socket.print(bufHeader);
Serial.println(bufHeader);
for(int split=0; split< length ; split+=STR_LENGTH_SPLIT)
{
if(length-split < STR_LENGTH_SPLIT)
{
socket.print(sendBuf.substring(split));
Serial.println(sendBuf.substring(split));
}
else
{
socket.print(sendBuf.substring(split,split+STR_LENGTH_SPLIT));
Serial.println(sendBuf.substring(split,split+STR_LENGTH_SPLIT));
}
}
Serial.println(sendBuf);
return 0;
}
开发者ID:Youngsoo,项目名称:iot-platform,代码行数:28,代码来源:transport.cpp
示例2: sendData
void Farmy::sendData(const char* device_id, String api_key, WiFiClient client, String data)
{
// Todo: use retry to connect internet.
Serial.println("Connected to Famry.");
Serial.println("Posted:" + data);
// Create HTTP POST Data
String url = String("/api/v0/user_devices/") + device_id + "/sensor_datas/";
client.print(String("POST ") + url + " HTTP/1.1\n"+ "Host: " + host + "\n");
client.print(String("Host: ") + host + "\n");
client.print("Content-Type: application/json\n");
client.print(String("X-Farmy-Api-Key: ") + api_key + "\n");
client.print("Content-Length: ");
client.print(data.length());
client.print("\n\n");
client.print(data);
Serial.println("Posted finished -----------");
delay(500);
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
}
开发者ID:arthurbryant,项目名称:farmy,代码行数:26,代码来源:Farmy.cpp
示例3: SendJSONstatusEvent
void EncodeNSendMessage::SendJSONstatusEvent(WiFiClient localclient, String MacAddr, HomeNodeDDI Hnode)
{
gsBufferWiFi="";
gsBufferWiFi+='{';
SendJSONobject("Job", "Event", false);
SendJSONobject("NodeID", (char *)MacAddr.c_str(), false);
gsBufferWiFi+="\"Status\":[";
localclient.print(gsBufferWiFi.c_str());
{
int i;
//JSONstatus1 // Presence
gsBufferWiFi="";
for(i = 0 ; i < strlen(JSONstatus1) ; i++)
{
gsBufferWiFi+=(char)pgm_read_byte_near(JSONstatus1 + i);
}
if(Hnode.proximity <= 50) // door open
{
gsBufferWiFi+="Mail";
}
else
{
gsBufferWiFi+="Empty";
}
gsBufferWiFi+="\"}";
localclient.print(gsBufferWiFi.c_str());
}
localclient.print("]}\n");
}
开发者ID:youkkwon,项目名称:smarthome,代码行数:31,代码来源:EncodeNSendMessage.cpp
示例4: attemptClient
// See if port 80 is accessable. Try 8080 as well.
boolean WiFiManager::attemptClient(const char *szUrl)
{
WiFiClient client;
int i;
Serial.print("Probe port 80");
for(i = 0; i < 5; i++)
{
if (client.connect(szUrl, httpPort)) {
client.stop();
Serial.println("Port 80 success");
return true;
}
Serial.print(".");
delay(20);
}
httpPort = 8080;
Serial.println("");
Serial.print("Probe port 8080");
for(i = 0; i < 5; i++)
{
if (client.connect(szUrl, httpPort)) {
client.stop();
Serial.println("Port 8080 success");
return true;
}
Serial.print(".");
delay(20);
}
Serial.println("");
Serial.println("No joy");
return false;
}
开发者ID:Dietmar-Franken,项目名称:WiFiWaterbedHeater,代码行数:34,代码来源:WiFiManager.cpp
示例5: String
/********************************************************************
connect establishes a connection to the Slack RTM API
********************************************************************/
bool ArduinoSlackBot::connect() {
// Step 1: Find WebSocket address via RTM API (https://api.slack.com/methods/rtm.start)
HTTPClient http;
String slackAddr = "https://slack.com/api/rtm.start?token=";
slackAddr = String(slackAddr + slackToken);
PRINTLN(slackAddr);
http.begin(slackAddr.c_str(), slackSSLFingerprint);
int httpCode = http.GET();
if (httpCode != HTTP_CODE_OK) {
PRINTF("HTTP GET failed with code %d\n", httpCode);
return false;
}
WiFiClient *client = http.getStreamPtr();
client->find("wss:\\/\\/");
String host = client->readStringUntil('\\');
String path = client->readStringUntil('"');
path.replace("\\/", "/");
// Step 2: Open WebSocket connection and register event handler
PRINTLN("WebSocket Host=" + host + " Path=" + path);
webSocket.beginSSL(host, 443, path, "", "");
webSocket.onEvent(webSocketEvent);
return true;
}
开发者ID:nullboundary,项目名称:ArduinoSlack,代码行数:32,代码来源:ArduinoSlackBot.cpp
示例6: HttpRequest
String DHwifi::HttpRequest( String req )
{
WiFiClient client;
char host[99];
m_remoteServer.toCharArray( host, 99);
const int httpPort = 80;
if (!client.connect(host, httpPort))
{
Serial.print( host );
Serial.println(" connection failed");
return "";
}
client.print(String("GET ") + req + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
String result;
// Read all the lines of the reply from server and print them to Serial
while (client.available())
{
result = client.readStringUntil('\r');
}
return result;
}
开发者ID:gpistoni,项目名称:DomoticHome,代码行数:29,代码来源:dhwifi.cpp
示例7: sendParameter
void EIoTCloudRestApi::sendParameter(const char * instaceParamId, String value)
{
WiFiClient client;
while(!client.connect(EIOT_CLOUD_ADDRESS, EIOT_CLOUD_PORT)) {
debug("connection failed");
wifiConnect();
}
String url = "";
// URL: /RestApi/SetParameter/[instance id]/[parameter id]/[value]
url += "/RestApi/SetParameter/" + String(instaceParamId) + "/" + value; // generate EasIoT cloud update parameter URL
debug("POST data to URL: ");
#ifdef DEBUG
char buff[300];
url.toCharArray(buff, 300);
debug(buff);
#endif
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + String(EIOT_CLOUD_ADDRESS) + "\r\n" +
"Connection: close\r\n" +
"Content-Length: 0\r\n" +
"\r\n");
delay(100);
while(client.available()){
#ifdef DEBUG
String line = client.readStringUntil('\r');
line.toCharArray(buff, 300);
debug(buff);
#endif
}
}
开发者ID:Ahmed-Azri,项目名称:EasyIoT-Cloud,代码行数:35,代码来源:EIoTCloudRestApi.cpp
示例8: stopAllExcept
void WiFiClient::stopAllExcept(WiFiClient* except)
{
for (WiFiClient* it = _s_first; it; it = it->_next) {
if (it != except) {
it->stop();
}
}
}
开发者ID:Chevelless396,项目名称:Arduino,代码行数:8,代码来源:WiFiClient.cpp
示例9: while
uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){
int res = client.read();
if(res == -1){
while(!client.available() && client.connected())
yield();
res = client.read();
}
return (uint8_t)res;
}
开发者ID:9mrcookie9,项目名称:Arduino,代码行数:9,代码来源:Parsing.cpp
示例10:
/**
* Wait for a WiFiClient to connect
*
* @returns: True if the client is ready, false otherwise.
*
*/
bool ESP8266WiFiMesh::waitForClient(WiFiClient curr_client, int max_wait)
{
int wait = max_wait;
while(curr_client.connected() && !curr_client.available() && wait--)
delay(3);
/* Return false if the client isn't ready to communicate */
if (WiFi.status() == WL_DISCONNECTED || !curr_client.connected())
return false;
return true;
}
开发者ID:gguuss,项目名称:Arduino,代码行数:18,代码来源:ESP8266WiFiMesh.cpp
示例11: connectClients
void connectClients() {
if (server.hasClient()) {
if (!serverClient || !serverClient.connected()) {
if (serverClient) serverClient.stop();
serverClient = server.available();
} else {
//no free/disconnected spot so reject
WiFiClient rejectClient = server.available();
rejectClient.stop();
}
}
}
开发者ID:,项目名称:,代码行数:12,代码来源:
示例12: MW_WifiTCPFinalread
extern "C" void MW_WifiTCPFinalread(uint8_t wifitcpindex, uint8_t *data, uint32_t serverport, int32_t *outStatus)
{
int libFcnOutput;
WiFiClient client = server[wifitcpindex].available();
if (client == true) {
libFcnOutput = client.read();
*data = (uint8_t) libFcnOutput;
*outStatus = (libFcnOutput != -1);
}
else
{
//When the client is not connected the status flag is accordingly toggled.
*outStatus = 0;
}
}
开发者ID:Logiant,项目名称:AgileRoboticControls,代码行数:16,代码来源:io_wrappers.cpp
示例13: doCommand
/*
* ======== doCommand ========
* execute the command in buffer and send results to client
*/
static void doCommand(char *buffer, int len, WiFiClient client)
{
if (buffer[1] == '\n' || buffer[1] == '\r') {
doWASD(buffer[0], client);
}
else {
#if 0
long int addr = 0;
int cnt = 0;
char *ptr;
/* get the address and count from the command */
getAddrCnt(buffer, len, &addr, &cnt);
/* send client cnt bytes starting from addr */
ptr = (char *)addr;
while (cnt-- > 0) {
int status;
if ((status = client.write(*ptr)) != 1) {
return;
}
ptr++;
}
#else
doWASD(' ', client);
#endif
}
}
开发者ID:energia,项目名称:emt,代码行数:32,代码来源:apLoop.cpp
示例14: sync_led
void sync_led(WiFiClient client) {
int new_brightness = -1;
while (client.available()) {
String line = client.readStringUntil('\r');
int ix_magic_ld = line.indexOf("ld");
int ix_colon = line.indexOf(":");
if (ix_magic_ld != -1) {
// Sync the LEDs
int ix_led = line.substring(ix_magic_ld + 2, ix_colon).toInt();
// The RGB value are encoded in Base 10 (not base 16) with "zero" padding.
// LD<LED_INDEX>: FFFFFF
// | | | |
// 0 2 C 2
String hexval = line.substring(ix_colon + 2);
long value = strtol(hexval.c_str(), NULL, 16);
int led_r = value >> 16;
int led_g = value >> 8 & 0xFF;
int led_b = value & 0xFF;
pixels.setPixelColor(ix_led, pixels.Color(led_r, led_g, led_b));
pixels.show();
#if DEBUG
Serial.print("LED#");
Serial.print(ix_led);
Serial.print(" <rgb>:");
Serial.print(led_r);
Serial.print(',');
Serial.print(led_g);
Serial.print(',');
Serial.print(led_b);
Serial.print('\n');
#endif
}
int ix_magic_br = line.indexOf("brightness");
if (ix_magic_br != -1) {
// Update the Brightness Values
new_brightness = line.substring(ix_colon + 2).toInt();
}
}
开发者ID:prashnts,项目名称:dotfiles,代码行数:46,代码来源:esp8266_fw.c
示例15: rcvCommand
void RobotHostInterface::rcvCommand(struct HostCommand *command)
{
byte rawCmd = 0xFF;
WiFiClient client = robotServer->available();
if (client) {
Serial.print("Robot Client connected...");
Serial.println("Waiting for a command......" );
while (client.available() == 0 ) {
delay( 100 );
}
rawCmd = (byte)client.read();
Serial.print("Raw Command: ");
Serial.print(rawCmd);
command->cmd = rawCmd >> 3;
command->arg = rawCmd & 0x07;
Serial.print(", Cmd: ");
Serial.print(command->cmd);
Serial.print(", arg: ");
Serial.println(command->arg);
if (command->cmd == CMD_ARRIVAL || command->cmd == CMD_WATCHDOG) {
if (command->cmd == CMD_ARRIVAL && getArrival()) {
rawCmd = CMD_ARRIVAL << 3;
setArrival(false);
} else if (command->cmd == CMD_WATCHDOG) {
rawCmd = 0xFF;
} else {
rawCmd = 0xFF;
}
}
/* send acknowledgement */
robotServer->write(rawCmd);
delay(100);
client.stop();
Serial.println("Client Disconnected.\n");
}
}
开发者ID:xingri,项目名称:dasdas,代码行数:45,代码来源:RobotHostInterface.cpp
示例16: Iotfy_getdata
String Iotfy_getdata(int no_of_bytes, int timeout)
{
int ctr=0;
int pt=millis()/1000;
String data="";
data.reserve(no_of_bytes);
while(1)
{
if(client.available())
{
char c=client.read();
data+=c;
Serial.print(c);
ctr++;
if(ctr==no_of_bytes)
break;
}
else
{
if(millis()/1000-pt>timeout)
{
pt=millis()/1000;
break;
}
}
}
Serial.println("calling disconnect");
client.flush();
client.stop();
return data;
}
开发者ID:Iotfy,项目名称:iotfy-libs,代码行数:32,代码来源:iotfy.cpp
示例17: loop
void loop() {
static boolean packetActive = false;
static uint8_t index = 0;
static boolean readingReturn = false;
static uint8_t rindex = 0;
if (!client.connected()) {
// try to connect to a new client
client = server.available();
} else {
// read data from the connected client
if (client.available() > 0) {
char c = client.read();
if (packetActive) {
commandBuffer[index] = c;
commandBuffer[++index] = 0;
if (c == EOP) {
comHandler();
packetActive = false;
}
}
else if (c == SOP) {
index = 0;
commandBuffer[index] = c;
commandBuffer[++index] = 0;
packetActive = true;
}
if (returnReady) {
client.println(returnBuffer);
server.println(returnBuffer);
Serial.println(returnBuffer);
returnReady = false;
}
}
}
if (Serial.available() && !returnReady) {
char s = Serial.read();
if (s == SOP) {
readingReturn = true;
rindex = 0;
}
if (readingReturn) {
returnBuffer[rindex] = s;
returnBuffer[++rindex] = 0;
if (s == EOP) {
returnReady = true;
}
}
}
}
开发者ID:delta-G,项目名称:robotESPcom,代码行数:57,代码来源:robotESPcom.cpp
示例18: transmitTele
void transmitTele()
{
Serial.println("tele");
while(!alreadyConnectedTele)
{
//attempt to save a client connecting to the server
teleClient = teleServer.available();
//if a client is connected, begin communication
if (teleClient) {
if (!alreadyConnectedTele) {
// clead out the input buffer:
teleClient.flush();
Serial.println("We have a new client");
alreadyConnectedTele = true;
}
}
}
for(int i = 0; i < 20; i++)
{
if (teleClient.available() > 0) {
// read the bytes incoming from the client:
char thisChar = teleClient.read();
// echo the bytes back to the client:
if(thisChar == '1')
teleServer.println(curSpeedKn * KNOTS_TO_MPS);
if(thisChar == '2')
teleServer.println(pollPing());
if(thisChar == '3')
teleServer.println(distToTar());
if(thisChar == '4')
teleServer.println(curLat);
if(thisChar == '5')
teleServer.println(curLon);
if(thisChar == '6')
teleServer.println(curHead);
// echo the bytes to the server as well:
Serial.println(thisChar);
}
}
}
开发者ID:DynamicBrute,项目名称:SARSRover,代码行数:56,代码来源:RoverFi.cpp
示例19: TCPhandler
void Con::TCPhandler(){
if (this->curType&CON_TCP){
if (ConSrv.hasClient()){
if (ConTcp.connected()){
ConTcp.stop();
}
ConTcp=ConSrv.available();
ConTcp.write("Hello\n",6);
}
}
}
开发者ID:it-guru,项目名称:ThIN,代码行数:11,代码来源:console.cpp
示例20: loop
void loop() {
// check the network connection once every 10 seconds:
delay(10000);
printCurrentNet();
// Trying to connect to http://hasthelargehadroncolliderdestroyedtheworldyet.com/
Serial5.println("Trying to connect to : www.hasthelargehadroncolliderdestroyedtheworldyet.com :");
httpRequest();
while( client.available() )
{
Serial5.print((char)(client.read()));
}
Serial5.println("END");
}
开发者ID:Bogaat,项目名称:Arduino,代码行数:14,代码来源:test.cpp
注:本文中的WiFiClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论