v12345vtm

peha-esp-telnet

May 8th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. /*
  2. https://youtu.be/srqj46WrCLY youtube=v12345vtm
  3.  
  4. basic concept of telnet session to peha domotics stm module
  5. send a XML request and print out the respons
  6.  
  7. */
  8.  
  9. #include <ESP8266WiFi.h>
  10.  
  11.  
  12. const char* ssid = "WiFi";
  13. const char* password = "pass";
  14. const char* host = "192.168.1.2"; //peha STM adress
  15. const int PehaXMLport = 6680; //xml telnet port fixed adres by peha
  16. const int PehaHTTPport = 80; //browser port http://192.168.1.2/modulestates.html
  17.  
  18. void setup() {
  19. Serial.begin(115200);
  20.  
  21. delay(10);
  22. Serial.println();
  23. Serial.println();
  24. Serial.print("Connecting to ");
  25. Serial.println(ssid);
  26. WiFi.mode(WIFI_STA);
  27. WiFi.begin(ssid, password);
  28.  
  29. while (WiFi.status() != WL_CONNECTED) {
  30. delay(500);
  31. Serial.print(".");
  32. }
  33.  
  34. Serial.println("");
  35. Serial.println("WiFi connected");
  36. Serial.println("IP address: ");
  37. Serial.println(WiFi.localIP());
  38.  
  39.  
  40.  
  41. Serial.print("connecting to peha STM ip ");
  42. Serial.println(host);
  43. Serial.print(" at port ");
  44. Serial.println(PehaXMLport + "\n\n\n");
  45.  
  46.  
  47. }
  48.  
  49.  
  50.  
  51. void loop() {
  52. WiFiClient client; //to connect to peha
  53.  
  54.  
  55. if (!client.connect(host, PehaXMLport)) {
  56. Serial.println("connection failed");
  57. return;
  58. }
  59.  
  60.  
  61.  
  62. // This will send the request to the server
  63. String tafellampTogglen = "<methodCall><methodName>service.stm.simInputEvent</methodName><params><param><value><i4>0</i4></value></param><param><value><i4>0</i4></value></param><param><value><i4>0</i4></value></param><param><value><i4>2</i4></value></param><param><value><i4>4</i4></value></param></params></methodCall>";
  64.  
  65. Serial.println( "xml request from esp8266 to peha:\n" + tafellampTogglen);
  66.  
  67. client.print(tafellampTogglen);
  68.  
  69.  
  70.  
  71. unsigned long timeout = millis();
  72. while (client.available() == 0) {
  73. if (millis() - timeout > 5000) {
  74. Serial.println(">>> Client Timeout !");
  75. client.stop();
  76. return;
  77. }
  78. }
  79.  
  80. // Read all the lines of the reply from server and print them to Serial
  81. Serial.println("\n\nstart of peha respons........");
  82. while (client.available()) {
  83. String peharespons = client.readStringUntil('\r');
  84. Serial.print(peharespons);
  85. }
  86.  
  87.  
  88. Serial.println("end of peha respons...........");
  89.  
  90.  
  91.  
  92. delay(300000);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment