Steuerung des Relais-Addierers mit einem alten Tintenstrahler + Arduino
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.5KB

  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <ESP8266WebServer.h>
  4. #include <DNSServer.h>
  5. #include <ESP8266mDNS.h>
  6. const char* ssid = "RelaisAddierer";
  7. //const char* password = "hacKNology";
  8. // DNS server
  9. const byte DNS_PORT = 53;
  10. DNSServer dnsServer;
  11. ESP8266WebServer server(80); //creating the server at port 80
  12. /* Soft AP network parameters */
  13. IPAddress apIP(192, 168, 4, 1);
  14. IPAddress netMsk(255, 255, 255, 0);
  15. volatile bool cts = true;
  16. void setup() {
  17. Serial.begin(19200);
  18. // put your setup code here, to run once:
  19. //Serial.print("Configuring access point...");
  20. /* You can remove the password parameter if you want the AP to be open. */
  21. WiFi.mode(WIFI_AP);
  22. WiFi.softAPConfig(apIP, apIP, netMsk);
  23. WiFi.softAP(ssid); /*, password*/
  24. delay(500); // Without delay I've seen the IP address blank
  25. /* Setup the DNS server redirecting all the domains to the apIP */
  26. dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
  27. dnsServer.start(DNS_PORT, "*", apIP);
  28. server.on("/form", formdata);
  29. server.on("/", handleroot);
  30. server.begin();
  31. }
  32. void handleroot() {
  33. server.send(200, "text/html", "<html><head></head><body><h1>Relais-Rechner-Steuerung</h1><form action=\"/form\" method=\"post\"><fieldset><input type=\"radio\" id=\"opplus\" name=\"op\" value=\"p\" checked><label for=\"opplus\"> +</label><br><input type=\"radio\" id=\"opminus\" name=\"op\" value=\"m\"><label for=\"opminus\"> -</label></fieldset><ul><li><label><input type=\"checkbox\" name=\"switch1\" value=\"on\">2^4</label><label><input type=\"checkbox\" name=\"switch2\" value=\"on\">2^3</label><label><input type=\"checkbox\" name=\"switch3\" value=\"on\">2^2</label><label><input type=\"checkbox\" name=\"switch4\" value=\"on\">2^1</label><label><input type=\"checkbox\" name=\"switch5\" value=\"on\">2^0</label></li><li><label><input type=\"checkbox\" name=\"switch6\" value=\"on\">2^4</label><label><input type=\"checkbox\" name=\"switch7\" value=\"on\">2^3</label><label><input type=\"checkbox\" name=\"switch8\" value=\"on\">2^2</label><label><input type=\"checkbox\" name=\"switch9\" value=\"on\">2^1</label><label><input type=\"checkbox\" name=\"switch10\" value=\"on\">2^0</label></li></ul><button type=\"submit\">Go!</button></form></body></html>");
  34. }
  35. void formdata() {
  36. if(cts) {
  37. cts = false;
  38. char op='+';
  39. char sw1='0',sw2='0',sw3='0',sw4='0',sw5='0',sw6='0',sw7='0',sw8='0',sw9='0',sw10='0';
  40. if(server.hasArg("op")) {
  41. if(server.arg("op").equals("m")) {
  42. op = '-';
  43. }
  44. }
  45. if(server.hasArg("switch1")) {
  46. sw1 = '1';
  47. }
  48. if(server.hasArg("switch2")) {
  49. sw2 = '1';
  50. }
  51. if(server.hasArg("switch3")) {
  52. sw3 = '1';
  53. }
  54. if(server.hasArg("switch4")) {
  55. sw4 = '1';
  56. }
  57. if(server.hasArg("switch5")) {
  58. sw5 = '1';
  59. }
  60. if(server.hasArg("switch6")) {
  61. sw6 = '1';
  62. }
  63. if(server.hasArg("switch7")) {
  64. sw7 = '1';
  65. }
  66. if(server.hasArg("switch8")) {
  67. sw8 = '1';
  68. }
  69. if(server.hasArg("switch9")) {
  70. sw9 = '1';
  71. }
  72. if(server.hasArg("switch10")) {
  73. sw10 = '1';
  74. }
  75. Serial.print('A');
  76. Serial.print(op);
  77. Serial.print(sw1);
  78. Serial.print(sw2);
  79. Serial.print(sw3);
  80. Serial.print(sw4);
  81. Serial.print(sw5);
  82. Serial.print(sw6);
  83. Serial.print(sw7);
  84. Serial.print(sw8);
  85. Serial.print(sw9);
  86. Serial.print(sw10);
  87. Serial.print('E');
  88. cts = true;
  89. }
  90. server.sendHeader("Location", String("/"), true);
  91. server.send ( 302, "text/plain", "");
  92. }
  93. void loop() {
  94. //DNS
  95. dnsServer.processNextRequest();
  96. server.handleClient();
  97. }