能源管控程序
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.
 
 
 
 
 
 

55 lines
1.1 KiB

  1. #ifdef ESP8266
  2. #include <ESP8266WiFi.h>
  3. #include <ESP8266mDNS.h>
  4. #include <ArduinoOTA.h>
  5. #else
  6. #include <ESP31BWiFi.h>
  7. #endif
  8. #include "ESPAsyncTCP.h"
  9. #include "SyncClient.h"
  10. const char* ssid = "**********";
  11. const char* password = "************";
  12. void setup(){
  13. Serial.begin(115200);
  14. WiFi.begin(ssid, password);
  15. if (WiFi.waitForConnectResult() != WL_CONNECTED) {
  16. Serial.printf("WiFi Failed!\n");
  17. return;
  18. }
  19. Serial.printf("WiFi Connected!\n");
  20. Serial.println(WiFi.localIP());
  21. #ifdef ESP8266
  22. ArduinoOTA.begin();
  23. #endif
  24. SyncClient client;
  25. if(!client.connect("www.google.com", 80)){
  26. Serial.println("Connect Failed");
  27. return;
  28. }
  29. client.setTimeout(2);
  30. if(client.printf("GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n") > 0){
  31. while(client.connected() && client.available() == 0){
  32. delay(1);
  33. }
  34. while(client.available()){
  35. Serial.write(client.read());
  36. }
  37. if(client.connected()){
  38. client.stop();
  39. }
  40. } else {
  41. client.stop();
  42. Serial.println("Send Failed");
  43. while(client.connected()) delay(0);
  44. }
  45. }
  46. void loop(){
  47. #ifdef ESP8266
  48. ArduinoOTA.handle();
  49. #endif
  50. }