vuk stijepovic 2020/0639

Dependencies:   Adafruit_GFX StrLib Util 19E042PIM_MB_PINS

Files at this revision

API Documentation at this revision

Comitter:
vukstijepovic
Date:
Sat Dec 11 16:25:57 2021 +0000
Commit message:
vuk stijepovic 2020/0639;

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
Adafruit_GFX_Config.h Show annotated file Show diff for this revision Revisions of this file
StrLib.lib Show annotated file Show diff for this revision Revisions of this file
Util.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 0de9c1e5bad1 19E042PIM_MB_PINS.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/19E042PIM_MB_PINS.lib	Sat Dec 11 16:25:57 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/tzwell/code/19E042PIM_MB_PINS/#5722459a201f
diff -r 000000000000 -r 0de9c1e5bad1 Adafruit_GFX.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX.lib	Sat Dec 11 16:25:57 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/nkhorman/code/Adafruit_GFX/#7fb1d4d3525d
diff -r 000000000000 -r 0de9c1e5bad1 Adafruit_GFX_Config.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX_Config.h	Sat Dec 11 16:25:57 2021 +0000
@@ -0,0 +1,1 @@
+#define GFX_WANT_ABSTRACTS
\ No newline at end of file
diff -r 000000000000 -r 0de9c1e5bad1 StrLib.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/StrLib.lib	Sat Dec 11 16:25:57 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/AkinoriHashimoto/code/StrLib/#7bc89a64bfbd
diff -r 000000000000 -r 0de9c1e5bad1 Util.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Util.lib	Sat Dec 11 16:25:57 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Phlaphead/code/Util/#3d93ff64fdee
diff -r 000000000000 -r 0de9c1e5bad1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 11 16:25:57 2021 +0000
@@ -0,0 +1,94 @@
+#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"
+#include<string>
+#include "stringUtils.h"
+
+#define SMALL_WAIT_MS 10
+#define I2C_ADDRESS         0x3c
+#define I2C_ADD_MBED    I2C_ADDRESS << 1
+#define OLED_HEIGHT_PX 64
+#define OLED_WIDTH_PX 128
+#define VOLTAGE_SCALER 3.3f
+
+AnalogIn pot1(MB_POT1);
+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);
+
+using namespace std;
+char* subpim = "mbed-sample-sub";
+char* pubpim = "mbed-sample-pub";
+const char* hostname = "broker.hivemq.com";
+int port = 1883;
+
+
+
+void messageArrived(MQTT::MessageData& md)
+{
+    char buf[100];
+    sprintf(buf, "V(POT1) = %1.2f\r\n", pot1*VOLTAGE_SCALER);
+    message.qos = MQTT::QOS0;
+    message.retained = false;
+    message.dup = false;
+    message.payload = (void*)buf;
+    message.payloadlen = strlen(buf)+1;
+    client.publish(pubpim, message);
+        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-11";
+
+    client.connect(data);
+    client.subscribe(subpim, MQTT::QOS0, messageArrived);
+    
+    
+
+    
+    
+    
+    myOLED.begin(); 
+    i2c_obj.frequency(400000);
+    
+    myOLED.clearDisplay();
+    myOLED.display();
+    
+    
+    while(1) {
+        thread_sleep_for(SMALL_WAIT_MS);
+        client.yield(1000);
+    }
+}
diff -r 000000000000 -r 0de9c1e5bad1 mbed-mqtt.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-mqtt.lib	Sat Dec 11 16:25:57 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-mqtt/#7fa219e87b3355e8a6fd281659697fe3a0c87630
diff -r 000000000000 -r 0de9c1e5bad1 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sat Dec 11 16:25:57 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#e4b81f67f939a0c0b11c147ce74aa367271e1279
diff -r 000000000000 -r 0de9c1e5bad1 mbed_app.json
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Sat Dec 11 16:25:57 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