-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0aacd3a
commit 4b980ca
Showing
4 changed files
with
346 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
Description: | ||
Use UNIT PoESP32 to create HTTP request | ||
before compiling: | ||
FastLED: https://github.com/FastLED/FastLED | ||
M5Atom: https://github.com/m5stack/M5Atom | ||
UNIT_PoESP32: https://github.com/m5stack/UNIT_PoESP32 | ||
*/ | ||
|
||
#include "M5Atom.h" | ||
#include "UNIT_PoESP32.h" | ||
|
||
UNIT_PoESP32 eth; | ||
|
||
typedef enum { kConfig = 0, kStart, kConnecting, kConnected } DTUState_t; | ||
|
||
DTUState_t State = kStart; | ||
|
||
void TaskLED(void *pvParameters) { | ||
while (1) { | ||
switch (State) { | ||
case kConfig: | ||
M5.dis.fillpix(0x0000ff); | ||
break; | ||
case kConnecting: | ||
M5.dis.fillpix(0xffff00); | ||
break; | ||
case kConnected: | ||
M5.dis.fillpix(0x00ff00); | ||
break; | ||
case kStart: | ||
M5.dis.fillpix(0xff0000); | ||
break; | ||
} | ||
for (int i = 100; i > 0; i--) { | ||
M5.dis.setBrightness(i); | ||
FastLED.show(); | ||
vTaskDelay(10 / portTICK_RATE_MS); | ||
} | ||
for (int i = 0; i < 100; i++) { | ||
M5.dis.setBrightness(i); | ||
FastLED.show(); | ||
vTaskDelay(10 / portTICK_RATE_MS); | ||
} | ||
} | ||
} | ||
|
||
String readstr; | ||
|
||
void setup() { | ||
M5.begin(true, false, true); | ||
eth.Init(&Serial2, 9600, 32, 26); | ||
|
||
xTaskCreatePinnedToCore(TaskLED, "TaskLED" // A name just for humans | ||
, | ||
4096 // This stack size can be checked & adjusted | ||
// by reading the Stack Highwater | ||
, | ||
NULL, | ||
1 // Priority, with 3 (configMAX_PRIORITIES - 1) | ||
// being the highest, and 0 being the lowest. | ||
, | ||
NULL, 0); | ||
delay(10); | ||
|
||
State = kStart; | ||
|
||
Serial.println("wait device connect"); | ||
while (!eth.checkDeviceConnect()) { | ||
delay(10); | ||
} | ||
|
||
Serial.println("device connected"); | ||
|
||
State = kConnecting; | ||
|
||
Serial.println("wait ethernet connect"); | ||
while (!eth.checkETHConnect()) { | ||
delay(10); | ||
} | ||
Serial.println("ethernet connected"); | ||
|
||
State = kConnected; | ||
|
||
readstr = eth.createHTTPClient(HEAD, APPLICATION_X_WWW_FORM_URLENCODED, | ||
"http://httpbin.org/get"); | ||
Serial.println(readstr); | ||
|
||
readstr = eth.createHTTPClient(GET, APPLICATION_X_WWW_FORM_URLENCODED, | ||
"http://httpbin.org/get"); | ||
Serial.println(readstr); | ||
|
||
readstr = eth.createHTTPClient(POST, APPLICATION_X_WWW_FORM_URLENCODED, | ||
"http://httpbin.org/post", | ||
"field1=value1&field2=value2"); | ||
Serial.println(readstr); | ||
|
||
readstr = eth.createHTTPClient(PUT, APPLICATION_X_WWW_FORM_URLENCODED, | ||
"http://httpbin.org/put"); | ||
Serial.println(readstr); | ||
|
||
readstr = eth.createHTTPClient(DELETE, APPLICATION_X_WWW_FORM_URLENCODED, | ||
"http://httpbin.org/delete"); | ||
Serial.println(readstr); | ||
} | ||
|
||
void loop() { | ||
if (Serial.available()) { | ||
char ch = Serial.read(); | ||
Serial2.write(ch); | ||
} | ||
if (Serial2.available()) { | ||
char ch = Serial2.read(); | ||
Serial.write(ch); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
Description: | ||
Use UNIT PoESP32 to connect to the MQTT server, and implement subscription | ||
and publishing messages. Check the status through Serial. When the MQTT | ||
connection is successful, Click Btn Public Topic Please install library | ||
before compiling: | ||
FastLED: https://github.com/FastLED/FastLED | ||
M5Atom: https://github.com/m5stack/M5Atom | ||
UNIT_PoESP32: https://github.com/m5stack/UNIT_PoESP32 | ||
*/ | ||
|
||
#include "M5Atom.h" | ||
#include "UNIT_PoESP32.h" | ||
|
||
UNIT_PoESP32 eth; | ||
|
||
typedef enum { kConfig = 0, kStart, kConnecting, kConnected } DTUState_t; | ||
|
||
DTUState_t State = kStart; | ||
|
||
void TaskLED(void *pvParameters) { | ||
while (1) { | ||
switch (State) { | ||
case kConfig: | ||
M5.dis.fillpix(0x0000ff); | ||
break; | ||
case kConnecting: | ||
M5.dis.fillpix(0xffff00); | ||
break; | ||
case kConnected: | ||
M5.dis.fillpix(0x00ff00); | ||
break; | ||
case kStart: | ||
M5.dis.fillpix(0xff0000); | ||
break; | ||
} | ||
for (int i = 100; i > 0; i--) { | ||
M5.dis.setBrightness(i); | ||
FastLED.show(); | ||
vTaskDelay(10 / portTICK_RATE_MS); | ||
} | ||
for (int i = 0; i < 100; i++) { | ||
M5.dis.setBrightness(i); | ||
FastLED.show(); | ||
vTaskDelay(10 / portTICK_RATE_MS); | ||
} | ||
} | ||
} | ||
|
||
String readstr; | ||
|
||
void setup() { | ||
M5.begin(true, false, true); | ||
eth.Init(&Serial2, 9600, 32, 26); | ||
|
||
xTaskCreatePinnedToCore(TaskLED, "TaskLED" // A name just for humans | ||
, | ||
4096 // This stack size can be checked & adjusted | ||
// by reading the Stack Highwater | ||
, | ||
NULL, | ||
1 // Priority, with 3 (configMAX_PRIORITIES - 1) | ||
// being the highest, and 0 being the lowest. | ||
, | ||
NULL, 0); | ||
delay(10); | ||
|
||
State = kStart; | ||
|
||
Serial.println("wait device connect"); | ||
while (!eth.checkDeviceConnect()) { | ||
delay(10); | ||
} | ||
|
||
Serial.println("device connected"); | ||
|
||
State = kConnecting; | ||
|
||
Serial.println("wait ethernet connect"); | ||
while (!eth.checkETHConnect()) { | ||
delay(10); | ||
} | ||
Serial.println("ethernet connected"); | ||
|
||
State = kConfig; | ||
|
||
Serial.println("wait mqtt connect"); | ||
while (!eth.createMQTTClient("120.77.157.90", "1883", "client_id", | ||
"user_name", "password")) { | ||
delay(10); | ||
} | ||
Serial.println("mqtt connected"); | ||
|
||
while (!eth.subscribeMQTTMsg("PoESP32_MQTT_D", "2")) { | ||
delay(10); | ||
} | ||
} | ||
|
||
void loop() { | ||
if (Serial.available()) { | ||
char ch = Serial.read(); | ||
Serial2.write(ch); | ||
} | ||
if (Serial2.available()) { | ||
char ch = Serial2.read(); | ||
Serial.write(ch); | ||
} | ||
eth.publicMQTTMsg("PoESP32_MQTT_U", "Hello From PoESP32", "2"); | ||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
Description: | ||
Use UNIT PoESP32 to connect TCP server | ||
before compiling: | ||
FastLED: https://github.com/FastLED/FastLED | ||
M5Atom: https://github.com/m5stack/M5Atom | ||
UNIT_PoESP32: https://github.com/m5stack/UNIT_PoESP32 | ||
*/ | ||
|
||
#include "M5Atom.h" | ||
#include "UNIT_PoESP32.h" | ||
|
||
UNIT_PoESP32 eth; | ||
|
||
typedef enum { kConfig = 0, kStart, kConnecting, kConnected } DTUState_t; | ||
|
||
DTUState_t State = kStart; | ||
|
||
void TaskLED(void *pvParameters) { | ||
while (1) { | ||
switch (State) { | ||
case kConfig: | ||
M5.dis.fillpix(0x0000ff); | ||
break; | ||
case kConnecting: | ||
M5.dis.fillpix(0xffff00); | ||
break; | ||
case kConnected: | ||
M5.dis.fillpix(0x00ff00); | ||
break; | ||
case kStart: | ||
M5.dis.fillpix(0xff0000); | ||
break; | ||
} | ||
for (int i = 100; i > 0; i--) { | ||
M5.dis.setBrightness(i); | ||
FastLED.show(); | ||
vTaskDelay(10 / portTICK_RATE_MS); | ||
} | ||
for (int i = 0; i < 100; i++) { | ||
M5.dis.setBrightness(i); | ||
FastLED.show(); | ||
vTaskDelay(10 / portTICK_RATE_MS); | ||
} | ||
} | ||
} | ||
|
||
String readstr; | ||
|
||
uint8_t data[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, | ||
0x06, 0x07, 0x08, 0x09, 0x10}; | ||
|
||
void setup() { | ||
M5.begin(true, false, true); | ||
eth.Init(&Serial2, 9600, 32, 26); | ||
|
||
xTaskCreatePinnedToCore(TaskLED, "TaskLED" // A name just for humans | ||
, | ||
4096 // This stack size can be checked & adjusted | ||
// by reading the Stack Highwater | ||
, | ||
NULL, | ||
1 // Priority, with 3 (configMAX_PRIORITIES - 1) | ||
// being the highest, and 0 being the lowest. | ||
, | ||
NULL, 0); | ||
delay(10); | ||
|
||
State = kStart; | ||
|
||
Serial.println("wait device connect"); | ||
while (!eth.checkDeviceConnect()) { | ||
delay(10); | ||
} | ||
|
||
Serial.println("device connected"); | ||
|
||
State = kConnecting; | ||
|
||
Serial.println("wait ethernet connect"); | ||
while (!eth.checkETHConnect()) { | ||
delay(10); | ||
} | ||
Serial.println("ethernet connected"); | ||
|
||
State = kConfig; | ||
|
||
Serial.println("Config TCP Client"); | ||
|
||
// AT+CIPSTART="TCP","192.168.3.102",8080 | ||
Serial.println("wait tcp connect"); | ||
while (!eth.createTCPClient("120.77.157.90", 1883)) { | ||
delay(10); | ||
} | ||
|
||
// while (!eth.configTCPClient("192.168.1.5", 60000)) { | ||
// delay(10); | ||
// } | ||
|
||
Serial.println("tcp connected"); | ||
|
||
if (eth.sendTCPData(data, sizeof(data))) { | ||
State = kConnected; | ||
|
||
} else { | ||
State = kStart; | ||
} | ||
} | ||
|
||
void loop() { | ||
if (Serial.available()) { | ||
char ch = Serial.read(); | ||
Serial2.write(ch); | ||
} | ||
if (Serial2.available()) { | ||
char ch = Serial2.read(); | ||
Serial.write(ch); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters