本文整理汇总了C++中EthernetServer类的典型用法代码示例。如果您正苦于以下问题:C++ EthernetServer类的具体用法?C++ EthernetServer怎么用?C++ EthernetServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EthernetServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loop
void loop()
{
static double v = 0.0;
static int count = 0;
EthernetClient client = server.available();
if (client)
{
while(true){
Serial.print("Printing data... count=");
Serial.println(count);
client.print(count++); client.print("; ");
client.print(0.00 + v, 2); client.print("; ");
client.print(1.23 + v, 2); client.print("; ");
client.print(2.098 + v, 3); client.print("; ");
client.print(3.83974 + v, 5); client.print("; ");
client.print(1.23 + v, 10); client.print("; ");
client.println(6.1276512765 + v, 10);
client.println("\r\n");
Serial.println("Done!");
delay(1000);
v += 0.2;
}
}else{
Serial.print("NO client!!! count=");
Serial.println(count++);
}
delay(1000);
}
示例2: loop
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
// we get a request
if (client) {
Serial.println(F("Client connected"));
// an http request ends with a blank line
boolean done = false;
while (client.connected() && !done) {
while (client.available () > 0 && !done) {
done = processIncomingByte (client.read ());
}
} // end of while client connected
// get ROV status values as json string
String rovStatus = getRovStatus();
// send a standard http response header
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/json"));
client.println(F("Connection: close")); // close after completion of the response
client.println(); // end of HTTP header
client.println(rovStatus);
// give the web browser time to receive the data
delay(10);
// close the connection:
client.stop();
Serial.println(F("Client disconnected"));
} // end of got a new client
} // end of loop
示例3: setup
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
Serial.println("ready");
}
示例4: loop
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client)
{
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
//*******************233333333333333333333333333333333333333333333*******
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: textml");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("<ml>");
break;
}
if (c == '\n')
{
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r')
{
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
示例5: loop
void loop() {
client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
if (client.find("GET /")) {
//INICIAR CRONOMETRAGEM
if (client.find("setCron=")) {
int charReaded = client.read();
if(charReaded == 49){
iniciarCronometragem();
}
}
//RETORNA O TEMPO DESDE O INICIO
if (client.find("getCron=")) {
int charReaded = client.read();
if(charReaded == 49){
getCronometragem();
}
}
}
}
Serial.println();
break;
}
client.println(" HTTP/1.1 200 OK ");
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
示例6: loopServer
void loopServer() {
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.print(readString); //print to serial monitor for debuging
//now output HTML data header
client.println(F("HTTP/1.1 200 OK")); //send new page on browser request
client.println(F("Content-Type: text/html"));
client.println();
client.println(F("Ok"));
delay(1);
//stopping client
client.stop();
if (readString.indexOf("R1=1") > 0){
soldoRelays[0]->On();
// Serial.println(">>>>>>>>>>>>");
// Serial.println("R1=1");
}
if (readString.indexOf("R2=1") > 0){
soldoRelays[1]->On();
// Serial.println(">>>>>>>>>>>>");
// Serial.println("R2=1");
}
if (readString.indexOf("R1=0") > 0){
soldoRelays[0]->Off();
// Serial.println(">>>>>>>>>>>>");
// Serial.println("R1=0");
}
if (readString.indexOf("R2=0") > 0){
soldoRelays[1]->Off();
// Serial.println(">>>>>>>>>>>>");
// Serial.println("R2=0");
}
readString="";
}
}
}
}
}
示例7: loop
void loop() {
// wait for a new client:
EthernetClient client = server.available();
// when the client sends the first byte, say hello:
if (client) {
if (!gotAMessage) {
Serial.println("We have a new client");
client.println("Hello, client!");
gotAMessage = true;
}
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.print(thisChar);
}
}
示例8: init
void NetworkConnectionClass::init()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("IP Address: ");
Serial.println(Ethernet.localIP());
sensorData = new LinkedList<SensorData*>();
state = RECV_DATA;
}
示例9: SetupWebServer
bool SetupWebServer ( void )
{
bool success = false;
#ifdef INTERFACE_ETHERNET
#ifdef ETHERNET_WEBSERVER
server.begin();
#endif //ETHERNET_WEBSERVER
#endif // INTERFACE_ETHERNET
return success;
}
示例10: setup
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
示例11: setup
void setup() {
Serial.begin(9600);
// Open serial communications and wait for port to open:
pinMode(3, INPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
// start the Ethernet connection and the server:
Ethernet.begin(mac);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
startRequest = false;
}
示例12: setup
void setup()
{
Serial.begin(9600);
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
IPAddress myIP(192,168,0,6);
Serial.println("Iniciando...");
Ethernet.begin(mac,myIP);
server.begin();
Serial.println("Rodando!!!");
}
示例13: setup
void setup()
{
Serial.begin(115200);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(SPK, OUTPUT);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
for(int i = 0; i < MAX_TASKS; i++)
{
taskList[i][0] = 0;
}
createTask(1, 0, 0);
Serial.println("setup complete");
}
示例14: setup
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print(F("server is at "));
Serial.println(Ethernet.localIP());
// setup Motors
setupMotors();
}
示例15: log_ethernet_logger
void log_ethernet_logger(const char * name, const char * value, const char * unit){
#ifdef DEBUG_ETHERNET_LOGGER
DEBUG_1("Starting");
#endif
#ifdef ETHERNET_ENABLE_SERVER
eth_server.print(millis(),DEC);
eth_server.write(",");
eth_server.write(name);
eth_server.write(",");
eth_server.write(value);
eth_server.write(",");
eth_server.write(unit);
eth_server.println(",");
#endif
#ifdef ETHERNET_ENABLE_MQTT
if (!mqtt_client.connected()){
#ifdef ETHERNET_MQTT_USER
mqtt_client.connect(ETHERNET_MQTT_CLIENT, ETHERNET_MQTT_USER, "ETHERNET_MQTT_PASS");
#else
mqtt_client.connect(ETHERNET_MQTT_CLIENT);
#endif
if (!mqtt_client.connected()){
return;
}
}
char *nbuf;
char *vbuf;
int len;
nbuf=(char*)malloc(sizeof(char)*(strlen(name)+1));
vbuf=(char*)malloc(sizeof(char)*(strlen(name)+1));
strcpy(nbuf, name);
strcpy(vbuf,value);
mqtt_client.publish(nbuf, vbuf);
free(nbuf);
free(vbuf);
#endif
#ifdef DEBUG_ETHERNET_LOGGER
DEBUG_1("Finishing");
#endif
}