msg.to = 'alex.6662594@gmail.com';
// msg.cc = 'alex9ufo@gmail.com';
if(msg.payload=='ON'){
msg.topic = '(NodeRed) 開燈啦';
msg.payload = '點燈泡開燈啦!' + msg.payload;
}
else if (msg.payload== 'OFF'){
msg.topic = '(NodeRed) 關燈啦';
msg.payload = '不知道是誰關燈啦!' + msg.payload;
}
else if (msg.payload== 'FLASH'){
msg.topic = '(NodeRed) 開關燈-閃爍-啦';
msg.payload = '不知道是誰開關燈-閃爍-啦!' + msg.payload;
}
return msg;
if (msg.payload === "ON")
msg.color ="lime";
if (msg.payload === "OFF")
msg.color ="red";
if (msg.payload === "FLASH")
msg.color ="blue";
return msg;
ESP32 Arduino 程式
/*LED_Breathing.ino Arduining.com 20 AUG 2015
Using NodeMCU Development Kit V1.0
Going beyond Blink sketch to see the blue LED breathing.
A PWM modulation is made in software because GPIO16 can't
be used with analogWrite().
*/
//#define BUILTIN_LED D0 // Led in NodeMCU at pin GPIO16 (D0).
#define BRIGHT 350 //max led intensity (1-500)
#define INHALE 1250 //Inhalation time in milliseconds.
#define PULSE INHALE*1000/BRIGHT
#define REST 5000 //Rest Between Inhalations.
String cmd="";
//----- Setup function. ------------------------
void setup() {
pinMode(BUILTIN_LED , OUTPUT); // LED pin as output.
Serial.begin(115200);
Serial.println("ESP32 Build LED ON , Received ON/OFF Message From Com Port!");
digitalWrite(BUILTIN_LED, HIGH); // turn the LED off.
}
//----- Loop routine. --------------------------
void loop()
{
if (Serial.available()) {
cmd = Serial.readStringUntil('\n');
if (cmd == "ON") {
digitalWrite(BUILTIN_LED, HIGH); // on
Serial.println("aan");
}
else if (cmd == "OFF") {
digitalWrite(BUILTIN_LED, LOW); // off
Serial.println("uit");
}
else {
for (int i=0;i<=5;i++){
digitalWrite(BUILTIN_LED, LOW); // off
delay(500);
digitalWrite(BUILTIN_LED, HIGH); // off
delay(500);
}
Serial.println("uit2");
}
} // if (Serial.available())
}
//==========================================================
Node-Red Json檔案 (中文會出現亂碼)
[{"id":"d4b0a646.09d0a8","type":"inject","z":"ba373d0d.51bee","name":"","topic":"","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":1160,"wires":[["ba8491c8.f2cb8","7ba48c78.00e084","35562ef.0e87cd2"]]},{"id":"3dd44f80.9aed4","type":"inject","z":"ba373d0d.51bee","name":"","topic":"","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":1200,"wires":[["ba8491c8.f2cb8","7ba48c78.00e084","35562ef.0e87cd2"]]},{"id":"7037ee2a.01b8","type":"inject","z":"ba373d0d.51bee","name":"","topic":"","payload":"FLASH","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":1240,"wires":[["35562ef.0e87cd2","7ba48c78.00e084","ba8491c8.f2cb8"]]},{"id":"35562ef.0e87cd2","type":"function","z":"ba373d0d.51bee","name":"Set Color","func":"if (msg.payload === \"ON\")\n msg.color =\"lime\";\n\nif (msg.payload === \"OFF\")\n msg.color =\"red\";\n\nif (msg.payload === \"FLASH\")\n msg.color =\"blue\";\n \n\n// msg.color = (msg.payload === \"ON\")?\"lime\":\"red\";\n\n\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":1300,"wires":[["82575e8a.45088","7099f2cc.0d030c"]]},{"id":"82575e8a.45088","type":"ui_text","z":"ba373d0d.51bee","group":"dbdf585d.7c3478","order":3,"width":"4","height":"4","name":"","label":"LED","format":"<font color={{msg.color}} ><i class=\"fa fa-circle\" style=\"font-size:24px;\"></i></font>","layout":"row-center","x":450,"y":1380,"wires":[]},{"id":"7099f2cc.0d030c","type":"function","z":"ba373d0d.51bee","name":"send mail","func":"msg.to = 'alex.6662594@gmail.com';\n// msg.cc = 'alex9ufo@gmail.com';\nif(msg.payload=='ON'){\n msg.topic = '(NodeRed) ????;\n msg.payload = '暺?瘜⊿??嚗? + msg.payload;\n}\nelse if (msg.payload== 'OFF'){\n msg.topic = '(NodeRed) ????;\n msg.payload = '銝?隤圈??嚗? + msg.payload;\n}\nelse if (msg.payload== 'FLASH'){\n msg.topic = '(NodeRed) ?????w?-??;\n msg.payload = '銝?隤圈???-?w?-?佗?' + msg.payload;\n}\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":440,"y":1300,"wires":[["707355ad.2c4cec","b993a548.3f8f78"]]},{"id":"707355ad.2c4cec","type":"e-mail","z":"ba373d0d.51bee","server":"smtp.gmail.com","port":"465","secure":true,"name":"","dname":"","x":590,"y":1320,"wires":[]},{"id":"b993a548.3f8f78","type":"debug","z":"ba373d0d.51bee","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":1280,"wires":[]},{"id":"7ba48c78.00e084","type":"debug","z":"ba373d0d.51bee","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":450,"y":1220,"wires":[]},{"id":"ba8491c8.f2cb8","type":"ui_text","z":"ba373d0d.51bee","group":"dbdf585d.7c3478","order":0,"width":0,"height":0,"name":"LED Message","label":"Arduino Reading","format":"{{msg.payload}}","layout":"col-center","x":460,"y":1160,"wires":[]},{"id":"44b321ce.0f161","type":"debug","z":"ba373d0d.51bee","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":1100,"wires":[]},{"id":"e4f03eb9.ff76d","type":"serial out","z":"ba373d0d.51bee","name":"Com4 ESP32","serial":"dff245b0.8b8268","x":620,"y":1020,"wires":[]},{"id":"5a0c336f.ef178c","type":"function","z":"ba373d0d.51bee","name":"ON","func":"msg.payload =\"ON\";\nreturn msg;\n","outputs":1,"noerr":0,"x":370,"y":1020,"wires":[["e4f03eb9.ff76d","44b321ce.0f161"]]},{"id":"982d9cb2.f9e22","type":"function","z":"ba373d0d.51bee","name":"OFF","func":"msg.payload=\"OFF\";\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":1060,"wires":[["e4f03eb9.ff76d","44b321ce.0f161"]]},{"id":"ff5351ae.46d22","type":"function","z":"ba373d0d.51bee","name":"FLASH","func":"msg.payload=\"FLASH\";\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":1100,"wires":[["e4f03eb9.ff76d","44b321ce.0f161"]]},{"id":"27bcb2a3.12006e","type":"switch","z":"ba373d0d.51bee","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"ON","vt":"str"},{"t":"cont","v":"OFF","vt":"str"},{"t":"cont","v":"FLASH","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":230,"y":1060,"wires":[["5a0c336f.ef178c"],["982d9cb2.f9e22"],["ff5351ae.46d22"]]},{"id":"3971be4f.844f92","type":"json","z":"ba373d0d.51bee","name":"","property":"payload","action":"str","pretty":false,"x":230,"y":980,"wires":[["27bcb2a3.12006e"]]},{"id":"dfe55825.b8d058","type":"debug","z":"ba373d0d.51bee","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":250,"y":920,"wires":[]},{"id":"aadb6fe0.6a831","type":"e-mail in","z":"ba373d0d.51bee","name":"","protocol":"IMAP","server":"imap.gmail.com","useSSL":true,"port":"993","box":"INBOX","disposition":"Read","repeat":"20","x":70,"y":960,"wires":[["dfe55825.b8d058","3971be4f.844f92"]]},{"id":"dbdf585d.7c3478","type":"ui_group","z":"","name":"LED Testing","tab":"89e5353f.12fef8","disp":true,"width":"4","collapse":false},{"id":"dff245b0.8b8268","type":"serial-port","z":"","serialport":"COM4","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false,"responsetimeout":"10000"},{"id":"89e5353f.12fef8","type":"ui_tab","name":"Tab","icon":"dashboard","order":0}]
沒有留言:
張貼留言