-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWiFi_Client.cpp
More file actions
71 lines (57 loc) · 1.8 KB
/
Copy pathWiFi_Client.cpp
File metadata and controls
71 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <Arduino.h>
#include <WiFi.h>
#include "Wire.h"
#include "Adafruit_SSD1306.h"
#include "Adafruit_GFX.h"
#define OLED_RESET -1
Adafruit_SSD1306 OLED(OLED_RESET);
const char ssid[] = "ssid";
const char password[] = "password";
byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
WiFiClient client;
char server_ip[] = "192.168.1.2";
const uint16_t port = 8888;
void setup()
{
Serial.begin(115200);
OLED.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
OLED.clearDisplay();
OLED.setTextColor(WHITE);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected with Router");
if (client.connect(server_ip,port)) {
Serial.println("client connected server");
client.print("Hello I'm Client from ");
client.println();
}
Serial.print("Local ip is : ");
Serial.println(WiFi.localIP());
Serial.print("Port is:"); Serial.println(port);
OLED.setCursor(10,0);
OLED.setTextSize(1);
client.println(WiFi.localIP());
OLED.println(WiFi.localIP());
OLED.display();
Serial.print("MAC Address is :"); WiFi.macAddress(mac);
Serial.print("MAC: "); Serial.print(mac[5],HEX); Serial.print(":"); Serial.print(mac[4],HEX);
Serial.print(":"); Serial.print(mac[3],HEX);
Serial.print(":"); Serial.print(mac[2],HEX);
Serial.print(":"); Serial.print(mac[1],HEX);
Serial.print(":"); Serial.println(mac[0],HEX);
}
void loop()
{
while(client.available()) {
char data = client.read();
Serial.write(data);
}
client.println("Hello"); delay(1000);
}