PMK_industrija_mikro4
Dependencies: rohm-rpr0521 rohm-sensor-hal Servo TextLCD
Revision 1:c49ad58c141d, committed 2021-07-05
- Comitter:
- emilija
- Date:
- Mon Jul 05 12:57:49 2021 +0000
- Parent:
- 0:c4a5143aeebc
- Commit message:
- PMK_INDUSTRIJA_MICRO4 VERZIJA2
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed_app.json | Show annotated file Show diff for this revision Revisions of this file |
diff -r c4a5143aeebc -r c49ad58c141d main.cpp --- a/main.cpp Wed Jun 30 20:52:55 2021 +0000 +++ b/main.cpp Mon Jul 05 12:57:49 2021 +0000 @@ -16,7 +16,8 @@ #include "rohm-rpr0521/rohm-rpr0521/rpr0521.h" // Blinking rate in milliseconds -#define BLINKING_RATE_MS 500 +#define BLINKING_RATE_MS + 500 int salji_boju=0; Serial pc(USBTX,USBRX); InterruptIn button(USER_BUTTON); @@ -26,8 +27,12 @@ MQTT::Message message; int button_pressed=0; +Timeout T3; + char* topic_sub = "PMK_industrija/micro4/#"; char* topic_pub = "PMK_industrija/micro1/proxy3"; +char* topic_pub2 = "PMK_industrija/micro1/color3"; +char* topic_pub1 = "PMK_industrija/micro1/echo/4"; Servo servo3(D7); @@ -134,7 +139,8 @@ printf("Payload %.*s\r\n", message.payloadlen, (char*)message.payload); char* poruka = (char*)message.payload; if(topic_name.find("servo3")!=std::string::npos) { - printf("AKTIVIRAN SERVO0\n"); + T3.detach(); + printf("AKTIVIRAN SERVO3\n"); for(float p=0; p<1.0; p += 0.1) { servo3 = p; @@ -144,10 +150,19 @@ servo3 = p; } + sprintf(buf, "servo3-AKTIVIRAN \r\n"); + message.qos = MQTT::QOS0; + message.retained = false; + message.dup = false; + message.payload = (void*)buf; + message.payloadlen = strlen(buf)+1; + client.publish(topic_pub1, message); } - else if(topic_name.find("proxy1")!=std::string::npos){ + else if(topic_name.find("color3")!=std::string::npos){ salji_boju=1; } + + else if(topic_name.find("LCD")!=std::string::npos){ lcd.cls(); @@ -155,6 +170,22 @@ } + else if(topic_name.find("echo")!=std::string::npos){ + if(poruka.find("connect")!=std::string::npos){ + fleg_start=1; + sprintf(buf, "echo4 \r\n"); + message.qos = MQTT::QOS0; + message.retained = false; + message.dup = false; + message.payload = (void*)buf; + message.payloadlen = strlen(buf)+1; + client.publish(topic_pub1, message); + } + else if(poruka.find("echo")!=std::string::npos){ + T3.detach(); + } + } + ++arrivedcount; } @@ -244,21 +275,25 @@ error = rpr0521_read_data(&dataProx[0]); if (!error){ - if(dataProx[0] > 50) { + T3.attach(&interuptT3,5); + if(dataProx[0] > 50 && !fleg_proxy) { + fleg_proxy1=1; printf("Pristigao je cep na lokaciju O.O O:'( \r\n "); char buf[100]; - sprintf(buf, "Cep je pristigao na proxy3 PS = %d",dataProx[0]); + sprintf(buf, "proxy3-AKTIV PS = %d",dataProx[0]); message.qos = MQTT::QOS0; message.retained = false; message.dup = false; message.payload = (void*)buf; message.payloadlen = strlen(buf)+1; client.publish(topic_pub, message); - salji_boju=1; + //salji_boju=1; } + else{fleg_proxy=0;} } if (salji_boju==1) { + T3.detach(); //salji_boju=0; //printf("Publishing data\r\n"); // QoS 0 @@ -304,7 +339,8 @@ //message.payload = (void*)buf; //message.payloadlen = strlen(buf)+1; //client.publish(topic_pub, message); - + T3.attach(&interruptT3,5); + salji_boju=0; }
diff -r c4a5143aeebc -r c49ad58c141d mbed_app.json --- a/mbed_app.json Wed Jun 30 20:52:55 2021 +0000 +++ b/mbed_app.json Mon Jul 05 12:57:49 2021 +0000 @@ -2,7 +2,7 @@ "config": { "wifi-ssid": { "help": "WiFi SSID", - "value": "\"HUAWEI Y6 2019\"" + "value": "\"rcopen\"" }, "wifi-password": { "help": "WiFi Password",