Timur Shamigulov
/
awaliawali2
potok
Revision 101:bd874520ab00, committed 2022-01-26
- Comitter:
- shamajin
- Date:
- Wed Jan 26 08:28:34 2022 +0000
- Parent:
- 100:642bee2ce173
- Commit message:
- 1
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 642bee2ce173 -r bd874520ab00 main.cpp --- a/main.cpp Thu Jan 20 09:44:11 2022 +0000 +++ b/main.cpp Wed Jan 26 08:28:34 2022 +0000 @@ -1,7 +1,7 @@ /* EXAMPLE */ #include "mbed.h" #include "hcsr04.h" - +#include "LiquidCrystal_I2C.h" //D12 TRIGGER D11 ECHO HCSR04 sensor(D12, D11); @@ -19,31 +19,26 @@ // Set the LCD address to 0x27 for a 16 chars and 2 line display LiquidCrystal_I2C lcd(0x4E, 16, 2); - +//Ticker Readdatchink_lcd_and_publish_; +Thread thread; + +void Readdatchink_lcd_and_publish(); + +//long distance = sensor.distance(); int main(int argc, char *argv[]) { + long distance = sensor.distance(); - /* EXAMPLE */ - long distance = sensor.distance(); - printf("distance %d \n",distance); - // initialize the LCD - lcd.begin(); - - - // initialize the LCD - lcd.begin(); + thread.start(Readdatchink_lcd_and_publish); + - // Turn on the blacklight and print a message. - lcd.backlight(); - lcd.print("Hello, world!"); - - - -//lcd.printf("Hi mbed World!\n"); printf("Starting IBM MQTT demo:\n"); - + + + + TCPSocket socket; @@ -54,7 +49,7 @@ printf("Error! No network inteface found.\n"); - return 0; + } @@ -68,7 +63,6 @@ printf("Error! _net->connect() returned: %d\r\n", rc); - return -1; } @@ -80,7 +74,7 @@ printf("Error! _socket.open() returned: %d\r\n", rc); - return -1; + } @@ -88,7 +82,7 @@ SocketAddress address; - net->gethostbyname("sandbox.rightech.io", + net->gethostbyname("dev.rightech.io", &address); @@ -106,7 +100,7 @@ printf("Error! _socket.connect() returned: %d\r\n", rc); - return -1; + } @@ -120,11 +114,11 @@ data.MQTTVersion = 3; - data.clientID.cstring = "mqtt-rudikrafikov-11r3lh"; + data.clientID.cstring = "mqtt-timur_shamigulov-blrz5n"; - data.username.cstring = "1234"; + data.username.cstring = "shama"; - data.password.cstring = "1234"; + data.password.cstring = "123"; if ((rc = client.connect(data)) != 0) @@ -140,9 +134,22 @@ + + printf("Demo concluded successfully \r\n"); + + + + +// Readdatchink_lcd_and_publish_.attach(&Readdatchink_lcd_and_publish, 5); +while (true) +{ + + wait_us(1000); + + MQTT::Message message; - char *topic = "temp"; + char *topic = "distance"; char buf[100]; @@ -163,7 +170,11 @@ // "{\"temperature\": %d}", temp); sprintf(buf, - "{\"distance\": %d}", distance); + "\%d", distance); + +// sprintf(buf, + + // "{\"distance\": %d}", distance); @@ -179,13 +190,42 @@ message.payloadlen = strlen(buf); - rc = client.publish(topic, message); + rc = client.publish(topic, message); printf("Message sent\n"); + + + + } - printf("Demo concluded successfully \r\n"); +return 0; + +} +void Readdatchink_lcd_and_publish() + +{ + long distance = sensor.distance(); +/* EXAMPLE */ + + // printf("distance %d \n",distance); + char buffer [15]; + sprintf (buffer, "Water level %d", distance); + // initialize the LCD + lcd.begin(); + + + // initialize the LCD + // lcd.begin(); + + // Turn on the blacklight and print a message. + lcd.backlight(); + lcd.print(buffer); + wait_us(1000); + + + + + } - return 0; -} \ No newline at end of file
diff -r 642bee2ce173 -r bd874520ab00 mbed_app.json --- a/mbed_app.json Thu Jan 20 09:44:11 2022 +0000 +++ b/mbed_app.json Wed Jan 26 08:28:34 2022 +0000 @@ -16,8 +16,8 @@ "*": { "target.network-default-interface-type": "WIFI", "nsapi.default-wifi-security": "WPA_WPA2", - "nsapi.default-wifi-ssid": "\"MI 8\"", - "nsapi.default-wifi-password": "\"55557777\"", + "nsapi.default-wifi-ssid": "\"Galaxy A51DCCF\"", + "nsapi.default-wifi-password": "\"12345678\"", "esp8266.tx": "D8", "esp8266.rx": "D2", "esp8266.socket-bufsize": "1024",