· 7 years ago · May 10, 2018, 05:04 PM
1#include <ESP8266WiFi.h>
2
3const char* ssid = "SjoenneTechNet"; //Change this value for your network
4const char* password = "Doritshave36"; //Change this value for your network
5boolean connected = false;
6boolean colorToggle = false;
7
8int inputPin = D3; // pushbutton connected to digital pin D3
9int val = 0; // variable to store the read value
10
11void WiFiEvent(WiFiEvent_t event) {
12 //Serial.printf("[WiFi-event] event: %d\n", event);
13
14 switch(event) {
15 case 3:
16 Serial.println("WiFi connected");
17 Serial.println("IP address: ");
18 Serial.println(WiFi.localIP());
19 connected = true;
20 break;
21 case 6:
22 Serial.println("WiFi lost connection");
23 connected = false;
24 break;
25 }
26
27 // 0 : WL_IDLE_STATUS when Wi-Fi is in process of changing between statuses
28 // 1 : WL_NO_SSID_AVAILin case configured SSID cannot be reached
29 // 3 : WL_CONNECTED after successful connection is established
30 // 4 : WL_CONNECT_FAILED if password is incorrect
31 // 6 : WL_DISCONNECTED if module is not configured in station mode
32
33}
34
35void setup() {
36 pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
37 pinMode(inputPin, INPUT); // set pin as input
38 Serial.begin(115200);
39 WiFi.disconnect(true);
40 delay(1000);
41 WiFi.onEvent(WiFiEvent);
42 WiFi.begin(ssid, password);
43 Serial.println("");
44
45 // Wait for connection
46 while (WiFi.status() != WL_CONNECTED) {
47 delay(500);
48 Serial.print(".");
49 }
50 Serial.println("");
51 Serial.print("Connected to ");
52 Serial.println(ssid);
53 Serial.print("IP address: ");
54 Serial.println(WiFi.localIP());
55
56}
57
58
59void loop() {
60
61
62
63
64
65 val = digitalRead(inputPin);
66 if(val == LOW){
67 sendkommando();
68 delay(1000);
69 }
70 else{
71
72 }
73}
74
75void sendkommando() {
76 const uint16_t port = 7777;
77 const char * host = "192.168.1.12";
78
79 WiFiClient client;
80
81 if (client.connect(host, port))
82 {
83 Serial.println("Connected to DSP... ");
84
85 char command[] = "echo standby 0 | cec-client -s -d 1";
86 client.write((uint8_t *)command, sizeof(command));
87
88
89 Serial.println("Command sent ... ");
90 }
91 else
92 {
93 Serial.println("connection failed ... ");
94 }
95
96
97}