krtina krtina u
Dependencies: Adafruit_GFX 19E042PIM_MB_PINS
Revision 0:3e4e1cfbfd0d, committed 2021-12-11
- Comitter:
- makotolagano
- Date:
- Sat Dec 11 10:15:42 2021 +0000
- Commit message:
- Samo jak gas ljubi brat ustima
Changed in this revision
diff -r 000000000000 -r 3e4e1cfbfd0d 19E042PIM_MB_PINS.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/19E042PIM_MB_PINS.lib Sat Dec 11 10:15:42 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/tzwell/code/19E042PIM_MB_PINS/#5722459a201f
diff -r 000000000000 -r 3e4e1cfbfd0d Adafruit_GFX.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_GFX.lib Sat Dec 11 10:15:42 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/kaizen/code/Adafruit_GFX/#3112550cc6a3
diff -r 000000000000 -r 3e4e1cfbfd0d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Dec 11 10:15:42 2021 +0000 @@ -0,0 +1,77 @@ +//MQTT & mbed libraries +#include "mb_pins.h" +#include "mbed.h" +#include "platform/mbed_thread.h" +#include "MQTTClientMbedOs.h" +//Oled libraries +#include "Adafruit_GFX.h" +#include "Adafruit_GFX_Config.h" +#include "Adafruit_SSD1306.h" + +//Macros +#define WAIT_MS 10 + +//I2C +#define I2C_ADDRESS 0x3c +#define I2C_ADD_MBED I2C_ADDRESS << 1 +#define OLED_HEIGHT_PX 64 +#define OLED_WIDTH_PX 128 + + +TCPSocket socket; +MQTTClient client(&socket); +MQTT::Message message; +WiFiInterface *wifi; + +I2C i2c_obj(MB_OLED_SDA, MB_OLED_SCL); +Adafruit_SSD1306_I2c myOLED(i2c_obj, PB_5, I2C_ADD_MBED, OLED_HEIGHT_PX, OLED_WIDTH_PX); + +char* topic_sub = "samo-jak-gas"; +const char* hostname = "broker.hivemq.com"; +int port = 1883; + +void messageArrived(MQTT::MessageData& md) +{ + MQTT::Message &message = md.message; + printf("Browser message: %.*s \n", message.payloadlen, (char*)message.payload); + + myOLED.clearDisplay(); + myOLED.setTextCursor(0, 0); + myOLED.printf("%.*s \r", message.payloadlen, (char*)message.payload); + myOLED.display(); +} + +int main() +{ + wifi = WiFiInterface::get_default_instance(); + + printf("Connecting to %s... \n",MBED_CONF_APP_WIFI_SSID); + int ret = wifi->connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2); + if(ret != 0){ + printf("Greska u povezivanju"); + return -1; + } + printf("Success!\n"); + + socket.open(wifi); + socket.connect(hostname,port); + + MQTTPacket_connectData data = MQTTPacket_connectData_initializer; + data.MQTTVersion = 3; + data.clientID.cstring = "Zolica"; + + client.connect(data); + client.subscribe(topic_sub, MQTT::QOS0, messageArrived); + + myOLED.begin(); + i2c_obj.frequency(400000); + + myOLED.clearDisplay(); + myOLED.display(); + + + while(1) { + thread_sleep_for(WAIT_MS); + client.yield(1000); + } +} \ No newline at end of file
diff -r 000000000000 -r 3e4e1cfbfd0d mbed-mqtt.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-mqtt.lib Sat Dec 11 10:15:42 2021 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-mqtt/#7fa219e87b3355e8a6fd281659697fe3a0c87630
diff -r 000000000000 -r 3e4e1cfbfd0d mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Sat Dec 11 10:15:42 2021 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#e4b81f67f939a0c0b11c147ce74aa367271e1279
diff -r 000000000000 -r 3e4e1cfbfd0d mbed_app.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Sat Dec 11 10:15:42 2021 +0000 @@ -0,0 +1,25 @@ +{ + "config": { + "wifi-ssid": { + "help": "WIFI SSID", + "value": "\"Zola\"" + }, + "wifi-password": { + "help": "Wifi Password", + "value": "\"zovemearmani\"" + } + }, + "target_overrides": { + "*": { + "platform.stdio-convert-newlines": true + }, + "NUCLEO_L476RG": { + "target.network-default-interface-type": "WIFI", + "esp8266.tx" : "PC_4", + "esp8266.rx" : "PC_5", + "esp8266.provide-default" : true, + "drivers.uart-serial-rxbuf-size" : 1024, + "drivers.uart-serial-txbuf-size" : 1024 + } + } +} \ No newline at end of file