Skip to content

Commit 4b980ca

Browse files
committed
add poesp32 example
1 parent 0aacd3a commit 4b980ca

4 files changed

Lines changed: 346 additions & 1 deletion

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
Description:
3+
Use UNIT PoESP32 to create HTTP request
4+
before compiling:
5+
FastLED: https://github.com/FastLED/FastLED
6+
M5Atom: https://github.com/m5stack/M5Atom
7+
UNIT_PoESP32: https://github.com/m5stack/UNIT_PoESP32
8+
*/
9+
10+
#include "M5Atom.h"
11+
#include "UNIT_PoESP32.h"
12+
13+
UNIT_PoESP32 eth;
14+
15+
typedef enum { kConfig = 0, kStart, kConnecting, kConnected } DTUState_t;
16+
17+
DTUState_t State = kStart;
18+
19+
void TaskLED(void *pvParameters) {
20+
while (1) {
21+
switch (State) {
22+
case kConfig:
23+
M5.dis.fillpix(0x0000ff);
24+
break;
25+
case kConnecting:
26+
M5.dis.fillpix(0xffff00);
27+
break;
28+
case kConnected:
29+
M5.dis.fillpix(0x00ff00);
30+
break;
31+
case kStart:
32+
M5.dis.fillpix(0xff0000);
33+
break;
34+
}
35+
for (int i = 100; i > 0; i--) {
36+
M5.dis.setBrightness(i);
37+
FastLED.show();
38+
vTaskDelay(10 / portTICK_RATE_MS);
39+
}
40+
for (int i = 0; i < 100; i++) {
41+
M5.dis.setBrightness(i);
42+
FastLED.show();
43+
vTaskDelay(10 / portTICK_RATE_MS);
44+
}
45+
}
46+
}
47+
48+
String readstr;
49+
50+
void setup() {
51+
M5.begin(true, false, true);
52+
eth.Init(&Serial2, 9600, 32, 26);
53+
54+
xTaskCreatePinnedToCore(TaskLED, "TaskLED" // A name just for humans
55+
,
56+
4096 // This stack size can be checked & adjusted
57+
// by reading the Stack Highwater
58+
,
59+
NULL,
60+
1 // Priority, with 3 (configMAX_PRIORITIES - 1)
61+
// being the highest, and 0 being the lowest.
62+
,
63+
NULL, 0);
64+
delay(10);
65+
66+
State = kStart;
67+
68+
Serial.println("wait device connect");
69+
while (!eth.checkDeviceConnect()) {
70+
delay(10);
71+
}
72+
73+
Serial.println("device connected");
74+
75+
State = kConnecting;
76+
77+
Serial.println("wait ethernet connect");
78+
while (!eth.checkETHConnect()) {
79+
delay(10);
80+
}
81+
Serial.println("ethernet connected");
82+
83+
State = kConnected;
84+
85+
readstr = eth.createHTTPClient(HEAD, APPLICATION_X_WWW_FORM_URLENCODED,
86+
"http://httpbin.org/get");
87+
Serial.println(readstr);
88+
89+
readstr = eth.createHTTPClient(GET, APPLICATION_X_WWW_FORM_URLENCODED,
90+
"http://httpbin.org/get");
91+
Serial.println(readstr);
92+
93+
readstr = eth.createHTTPClient(POST, APPLICATION_X_WWW_FORM_URLENCODED,
94+
"http://httpbin.org/post",
95+
"field1=value1&field2=value2");
96+
Serial.println(readstr);
97+
98+
readstr = eth.createHTTPClient(PUT, APPLICATION_X_WWW_FORM_URLENCODED,
99+
"http://httpbin.org/put");
100+
Serial.println(readstr);
101+
102+
readstr = eth.createHTTPClient(DELETE, APPLICATION_X_WWW_FORM_URLENCODED,
103+
"http://httpbin.org/delete");
104+
Serial.println(readstr);
105+
}
106+
107+
void loop() {
108+
if (Serial.available()) {
109+
char ch = Serial.read();
110+
Serial2.write(ch);
111+
}
112+
if (Serial2.available()) {
113+
char ch = Serial2.read();
114+
Serial.write(ch);
115+
}
116+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Description:
3+
Use UNIT PoESP32 to connect to the MQTT server, and implement subscription
4+
and publishing messages. Check the status through Serial. When the MQTT
5+
connection is successful, Click Btn Public Topic Please install library
6+
before compiling:
7+
FastLED: https://github.com/FastLED/FastLED
8+
M5Atom: https://github.com/m5stack/M5Atom
9+
UNIT_PoESP32: https://github.com/m5stack/UNIT_PoESP32
10+
*/
11+
12+
#include "M5Atom.h"
13+
#include "UNIT_PoESP32.h"
14+
15+
UNIT_PoESP32 eth;
16+
17+
typedef enum { kConfig = 0, kStart, kConnecting, kConnected } DTUState_t;
18+
19+
DTUState_t State = kStart;
20+
21+
void TaskLED(void *pvParameters) {
22+
while (1) {
23+
switch (State) {
24+
case kConfig:
25+
M5.dis.fillpix(0x0000ff);
26+
break;
27+
case kConnecting:
28+
M5.dis.fillpix(0xffff00);
29+
break;
30+
case kConnected:
31+
M5.dis.fillpix(0x00ff00);
32+
break;
33+
case kStart:
34+
M5.dis.fillpix(0xff0000);
35+
break;
36+
}
37+
for (int i = 100; i > 0; i--) {
38+
M5.dis.setBrightness(i);
39+
FastLED.show();
40+
vTaskDelay(10 / portTICK_RATE_MS);
41+
}
42+
for (int i = 0; i < 100; i++) {
43+
M5.dis.setBrightness(i);
44+
FastLED.show();
45+
vTaskDelay(10 / portTICK_RATE_MS);
46+
}
47+
}
48+
}
49+
50+
String readstr;
51+
52+
void setup() {
53+
M5.begin(true, false, true);
54+
eth.Init(&Serial2, 9600, 32, 26);
55+
56+
xTaskCreatePinnedToCore(TaskLED, "TaskLED" // A name just for humans
57+
,
58+
4096 // This stack size can be checked & adjusted
59+
// by reading the Stack Highwater
60+
,
61+
NULL,
62+
1 // Priority, with 3 (configMAX_PRIORITIES - 1)
63+
// being the highest, and 0 being the lowest.
64+
,
65+
NULL, 0);
66+
delay(10);
67+
68+
State = kStart;
69+
70+
Serial.println("wait device connect");
71+
while (!eth.checkDeviceConnect()) {
72+
delay(10);
73+
}
74+
75+
Serial.println("device connected");
76+
77+
State = kConnecting;
78+
79+
Serial.println("wait ethernet connect");
80+
while (!eth.checkETHConnect()) {
81+
delay(10);
82+
}
83+
Serial.println("ethernet connected");
84+
85+
State = kConfig;
86+
87+
Serial.println("wait mqtt connect");
88+
while (!eth.createMQTTClient("120.77.157.90", "1883", "client_id",
89+
"user_name", "password")) {
90+
delay(10);
91+
}
92+
Serial.println("mqtt connected");
93+
94+
while (!eth.subscribeMQTTMsg("PoESP32_MQTT_D", "2")) {
95+
delay(10);
96+
}
97+
}
98+
99+
void loop() {
100+
if (Serial.available()) {
101+
char ch = Serial.read();
102+
Serial2.write(ch);
103+
}
104+
if (Serial2.available()) {
105+
char ch = Serial2.read();
106+
Serial.write(ch);
107+
}
108+
eth.publicMQTTMsg("PoESP32_MQTT_U", "Hello From PoESP32", "2");
109+
delay(1000);
110+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
Description:
3+
Use UNIT PoESP32 to connect TCP server
4+
before compiling:
5+
FastLED: https://github.com/FastLED/FastLED
6+
M5Atom: https://github.com/m5stack/M5Atom
7+
UNIT_PoESP32: https://github.com/m5stack/UNIT_PoESP32
8+
*/
9+
10+
#include "M5Atom.h"
11+
#include "UNIT_PoESP32.h"
12+
13+
UNIT_PoESP32 eth;
14+
15+
typedef enum { kConfig = 0, kStart, kConnecting, kConnected } DTUState_t;
16+
17+
DTUState_t State = kStart;
18+
19+
void TaskLED(void *pvParameters) {
20+
while (1) {
21+
switch (State) {
22+
case kConfig:
23+
M5.dis.fillpix(0x0000ff);
24+
break;
25+
case kConnecting:
26+
M5.dis.fillpix(0xffff00);
27+
break;
28+
case kConnected:
29+
M5.dis.fillpix(0x00ff00);
30+
break;
31+
case kStart:
32+
M5.dis.fillpix(0xff0000);
33+
break;
34+
}
35+
for (int i = 100; i > 0; i--) {
36+
M5.dis.setBrightness(i);
37+
FastLED.show();
38+
vTaskDelay(10 / portTICK_RATE_MS);
39+
}
40+
for (int i = 0; i < 100; i++) {
41+
M5.dis.setBrightness(i);
42+
FastLED.show();
43+
vTaskDelay(10 / portTICK_RATE_MS);
44+
}
45+
}
46+
}
47+
48+
String readstr;
49+
50+
uint8_t data[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
51+
0x06, 0x07, 0x08, 0x09, 0x10};
52+
53+
void setup() {
54+
M5.begin(true, false, true);
55+
eth.Init(&Serial2, 9600, 32, 26);
56+
57+
xTaskCreatePinnedToCore(TaskLED, "TaskLED" // A name just for humans
58+
,
59+
4096 // This stack size can be checked & adjusted
60+
// by reading the Stack Highwater
61+
,
62+
NULL,
63+
1 // Priority, with 3 (configMAX_PRIORITIES - 1)
64+
// being the highest, and 0 being the lowest.
65+
,
66+
NULL, 0);
67+
delay(10);
68+
69+
State = kStart;
70+
71+
Serial.println("wait device connect");
72+
while (!eth.checkDeviceConnect()) {
73+
delay(10);
74+
}
75+
76+
Serial.println("device connected");
77+
78+
State = kConnecting;
79+
80+
Serial.println("wait ethernet connect");
81+
while (!eth.checkETHConnect()) {
82+
delay(10);
83+
}
84+
Serial.println("ethernet connected");
85+
86+
State = kConfig;
87+
88+
Serial.println("Config TCP Client");
89+
90+
// AT+CIPSTART="TCP","192.168.3.102",8080
91+
Serial.println("wait tcp connect");
92+
while (!eth.createTCPClient("120.77.157.90", 1883)) {
93+
delay(10);
94+
}
95+
96+
// while (!eth.configTCPClient("192.168.1.5", 60000)) {
97+
// delay(10);
98+
// }
99+
100+
Serial.println("tcp connected");
101+
102+
if (eth.sendTCPData(data, sizeof(data))) {
103+
State = kConnected;
104+
105+
} else {
106+
State = kStart;
107+
}
108+
}
109+
110+
void loop() {
111+
if (Serial.available()) {
112+
char ch = Serial.read();
113+
Serial2.write(ch);
114+
}
115+
if (Serial2.available()) {
116+
char ch = Serial2.read();
117+
Serial.write(ch);
118+
}
119+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Device Control
88
url=https://github.com/m5stack/M5Atom
99
architectures=esp32
1010
includes=M5Atom.h
11-
depends=FastLED,UNIT_ENV,Adafruit MCP4725,Adafruit TCS34725,Adafruit NeoPixel,MAX30100lib,MFRC522_I2C,M5GFX,M5_BM8563,M5_ADS1100,M5_ADS1115,M5_FPC1020A,HX711 Arduino Library,PCA9554,TinyGPSPlus-ESP32,Adafruit SGP30 Sensor,FFT,TFTTerminal,ClosedCube TCA9548A,Ethernet2,ESP8266Audio,M5_EzData,ArduinoJson,PubSubClient,UNIT_SONIC,PoE_CAM,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,ATOM_DTU_CAT1
11+
depends=FastLED,UNIT_ENV,Adafruit MCP4725,Adafruit TCS34725,Adafruit NeoPixel,MAX30100lib,MFRC522_I2C,M5GFX,M5_BM8563,M5_ADS1100,M5_ADS1115,M5_FPC1020A,HX711 Arduino Library,PCA9554,TinyGPSPlus-ESP32,Adafruit SGP30 Sensor,FFT,TFTTerminal,ClosedCube TCA9548A,Ethernet2,ESP8266Audio,M5_EzData,ArduinoJson,PubSubClient,UNIT_SONIC,PoE_CAM,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,ATOM_DTU_CAT1,UNIT_PoESP32

0 commit comments

Comments
 (0)