Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Ethernet.h>
- // Enter a MAC address and IP address for your controller below.
- // The IP address will be dependent on your local network:
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- IPAddress ip(10, 1, 1, 10);
- EthernetServer server(80);
- void setup()
- {
- Serial.begin(115200);
- Ethernet.begin(mac, ip);
- server.begin();
- pinMode(A0, 1);
- pinMode(A1, 1);
- }
- void loop()
- {
- // listen for incoming clients
- EthernetClient client = server.available(); //inicia o webservice
- if (client) {
- // an http request ends with a blank line
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- if (c == '\n' && currentLineIsBlank) {
- client.println("HTTP/1.1 200 OK"); //cria um webservice HTTP
- client.println("Content-Type: text/xml"); //cria um documento do tipo XML
- client.println("Connection: close"); //fecha a conexão
- client.println("Refresh: .05"); //Recarrega a pagina a cada .05seg
- client.println();
- client.println("<!DOCTYPE XML>"); //estrutura XML
- client.println("<xml>");
- client.println("Leitura POT ");
- client.println(analogRead(A0)/4); //le o valor do potenciometro
- client.println("</xml>");
- break;
- }
- if (c == '\n') {
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement