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