Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- pots on 8,9 analog channels change background colour and fill color of svg
- */
- #include <SPI.h>
- #include <NativeEthernet.h>
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
- };
- IPAddress ip(10, 1, 0, 177);
- EthernetServer server(80);
- void initClient(EthernetClient client);
- void setup() {
- delay(5000); //you want this delay. reason: tl;dr
- Serial.begin(9600);
- Ethernet.begin(mac, ip);
- if (Ethernet.linkStatus() == LinkOFF) {
- Serial.println("Ethernet cable is not connected.");
- }
- // start the server
- server.begin();
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- }
- void loop() {
- // listen for incoming clients
- EthernetClient client = server.available();
- if (client) {
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- // Serial.write(c);
- /*
- client disconnected
- GET / HTTP/1.1
- Host: 10.1.0.177
- User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*\/*;q=0.8
- Accept-Language: en-US,en;q=0.5
- Accept-Encoding: gzip, deflate
- Connection: keep-alive
- Upgrade-Insecure-Requests: 1
- Cache-Control: max-age=0
- client disconnected
- */
- if (c == '\n' && currentLineIsBlank) {
- initClient(client);
- int sensorReading0 = analogRead(8);
- int sensorReading1 = analogRead(9);
- client.print("<svg version=\"1.1\" \n baseProfile=\"full\"\n width=\"300\" height=\"200\"\n xmlns=\"http://www.w3.org/2000/svg\">\n <rect width=\"100%\" height=\"100%\" fill=\"#");
- client.print(sensorReading0);
- client.print("\" /> <circle cx=\"150\" cy=\"100\" r=\"90\" fill=\"#");
- client.print(sensorReading1);
- client.print("\" />\n</svg>");
- client.println("<br />");
- client.println("</html>");
- 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");
- }
- }
- void initClient(EthernetClient client){
- // send a standard http response header
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- 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>");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement