Test 3 2020/0690

Dependencies:   Adafruit_GFX 19E042PIM_MB_PINS

Files at this revision

API Documentation at this revision

Comitter:
milant
Date:
Sat Dec 11 16:23:52 2021 +0000
Commit message:
Test 3 2020/0690

Changed in this revision

19E042PIM_MB_PINS.lib Show annotated file Show diff for this revision Revisions of this file
Adafruit_GFX.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-mqtt.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib 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 000000000000 -r 380913e3e77e 19E042PIM_MB_PINS.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/19E042PIM_MB_PINS.lib	Sat Dec 11 16:23:52 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/tzwell/code/19E042PIM_MB_PINS/#5722459a201f
diff -r 000000000000 -r 380913e3e77e Adafruit_GFX.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX.lib	Sat Dec 11 16:23:52 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/kaizen/code/Adafruit_GFX/#3112550cc6a3
diff -r 000000000000 -r 380913e3e77e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 11 16:23:52 2021 +0000
@@ -0,0 +1,78 @@
+// Importing libraries
+#include "mb_pins.h"
+#include "mbed.h"
+#include "platform/mbed_thread.h"
+#include "MQTTClientMbedOs.h"
+#include "Adafruit_GFX.h"
+#include "Adafruit_GFX_Config.h"
+#include "Adafruit_SSD1306.h"
+
+// Macros
+#define WAIT_MS             10
+ 
+// I2C Macros 
+#define I2C_ADDRESS         0x3c
+#define I2C_ADD_MBED        I2C_ADDRESS << 1
+// OLED Macros
+#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 = "pubpim";
+char* topic_sub = "subpim";
+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 = "pim";
+ 
+    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 380913e3e77e mbed-mqtt.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-mqtt.lib	Sat Dec 11 16:23:52 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-mqtt/#7fa219e87b3355e8a6fd281659697fe3a0c87630
diff -r 000000000000 -r 380913e3e77e mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sat Dec 11 16:23:52 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#e4b81f67f939a0c0b11c147ce74aa367271e1279
diff -r 000000000000 -r 380913e3e77e mbed_app.json
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Sat Dec 11 16:23:52 2021 +0000
@@ -0,0 +1,25 @@
+{
+    "config": {
+        "wifi-ssid": {
+            "help": "WIFI SSID",
+            "value": "\"cvele97\""
+        },
+        "wifi-password": {
+            "help": "Wifi Password",
+            "value": "\"ekonomskitigar2021\""
+        }
+    },
+    "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