Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include <WiFi.h>
  3.  
  4. #include "SSD1306.h"
  5.  
  6. const char* ssid = "ezff";
  7. const char* password = "password";
  8. const char* host = "192.168.4.1";
  9.  
  10. SSD1306 display(0x3c, 5, 4);
  11.  
  12. void mylog(const char* message);
  13.  
  14. void setup() {
  15.     WiFi.begin(ssid, password);
  16.  
  17.     while (WiFi.status() != WL_CONNECTED) {
  18.         delay(100);
  19.     }
  20.  
  21.     display.init();
  22.     display.setLogBuffer(5, 30);
  23.     //display.flipScreenVertically();
  24.     mylog(WiFi.localIP().toString().c_str());
  25. }
  26.  
  27. void loop() {
  28.     if (WiFi.status() != WL_CONNECTED) {
  29.         WiFi.begin();
  30.     }
  31.  
  32.     WiFiClient client;
  33.     const int port = 10000;
  34.     if (client.connect(host, port)) {
  35.         mylog("connected");
  36.         while (client.connected()) {
  37.             client.print("LED(ON);");
  38.             delay(1000);
  39.             client.print("LED(OFF);");
  40.             delay(1000);
  41.             while (client.available()) {
  42.                 client.read();
  43.             }
  44.         }
  45.  
  46.         client.stop();
  47.     } else {
  48.         mylog("connection failed");
  49.         delay(1000);
  50.     }
  51. }
  52.  
  53. void mylog(const char* message) {
  54.     display.clear();
  55.     display.setTextAlignment(TEXT_ALIGN_LEFT);
  56.     display.setFont(ArialMT_Plain_10);
  57.     display.println(message);
  58.     display.drawLogBuffer(0, 0);
  59.     display.display();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement