.

Dependencies:   mbed Adafruit_GFX 19E042PIM_MB_PINS

Files at this revision

API Documentation at this revision

Comitter:
dobrica
Date:
Sat Dec 11 16:12:48 2021 +0000
Child:
1:5b8e39e7496c
Commit message:
Dobrica Stosic 2019/0277

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.bld 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/19E042PIM_MB_PINS.lib	Sat Dec 11 16:12:48 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/tzwell/code/19E042PIM_MB_PINS/#5722459a201f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX.lib	Sat Dec 11 16:12:48 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/dobrica/code/Adafruit_GFX/#0680af285739
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 11 16:12:48 2021 +0000
@@ -0,0 +1,132 @@
+// TEST 3
+
+
+//Biblioteke
+#include "mbed.h"
+#include "mb_pins.h"
+
+#include "platform/mbed_thread.h"
+#include "MQTTClientMbedOs.h"
+
+#include "Adafruit_GFX.h"
+#include "Adafruit_GFX_Config.h"
+#include "Adafruit_SSD1306.h"
+
+
+#define BLINKING                                                             250
+#define VOLTAGE_SCALER                                                      3.3f
+#define TIMEOUT                                                             1000    
+#define MAX_NETWORKS                                                          15
+#define PRINTF_DELAY_MS  
+
+
+#define I2C_REAL_ADD                                                        0x3c
+#define I2C_ADDRESS                                            I2C_REAL_ADD << 1
+#define OLED_HEIGHT                                                           64
+#define OLED_WIDTH                                                           128
+
+//Globalne promenljive
+WiFiInterface *wifi;
+TCPSocket socket;
+MQTTClient client(&socket);
+MQTT::Message message;
+
+I2C i2c(PB_14,PB_13);
+Adafruit_SSD1306_I2c myOled(i2c,PB_5,I2C_ADDRESS,OLED_HEIGHT,OLED_WIDTH);
+
+char* topic = "pubpim";
+char* topic_sub = "subpim";
+const char* hostname = "broker.hivemq.com";
+int arrivedcount = 0;
+int port = 8000;
+
+
+
+//Funkcije
+int scan_networks(WiFiInterface *wifi)
+{
+    myOled.begin();
+    myOled.setTextCursor(5,5);
+    myOled.setTextSize(15);
+    
+    printf("Scan:\n");
+    myOled.writeChar('S');
+    myOled.writeChar('c');
+    myOled.writeChar('a');
+    myOled.writeChar('n');
+    myOled.writeChar(':');
+    
+    int count = wifi->scan(NULL, 0);
+    if (count <= 0)
+    {
+        printf("scan() failed with return value: %d\n", count);
+        return 0;
+    }
+    count = count < MAX_NETWORKS ? count : MAX_NETWORKS;
+    
+
+    WiFiAccessPoint *ap = new WiFiAccessPoint[count];
+    count = wifi->scan(ap, count);
+    
+    if (count <= 0) 
+    {
+        printf("scan() failed with return value: %d\n", count);
+        return 0;
+    }
+    
+    printf("%d networks available.\n", count);
+    delete[] ap;
+    return count;
+}
+ void messageArrived(MQTT::MessageData& md)
+{
+    MQTT::Message &message = md.message;
+    //printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\r\n", message.qos, message.retained, message.dup, message.id);
+    printf("Message from the browser: %.*s\r\n", message.payloadlen, (char*)message.payload);
+    ++arrivedcount;
+}
+
+
+
+//Glavni program
+int main()
+{
+    wifi = WiFiInterface::get_default_instance();
+    if (!wifi) {
+        printf("ERROR\n");
+        return -1;
+    }
+    
+    
+    int count = scan_networks(wifi);
+    if (count == 0) {
+        printf("\n");
+        return -1;
+    }
+    
+    printf("\nConnecting 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("\nConnection error: %d\n", ret);
+        return -1;
+    }
+    printf("Success\n\n"); 
+    
+    
+    //Ostvarivanje konekcije
+    socket.open(wifi);
+    socket.connect(hostname, port);
+    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
+    data.MQTTVersion = 3;
+    data.clientID.cstring = "pim-30";
+    client.connect(data);
+    
+    // Connect
+    int rc = 0;
+    if ((rc = client.connect(data)) != 0)
+        printf("rc from MQTT connect is %d\r\n", rc);
+ 
+    if ((rc = client.subscribe(topic_sub, MQTT::QOS2, messageArrived)) != 0)
+        printf("rc from MQTT subscribe is %d\r\n", rc);
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-mqtt.lib	Sat Dec 11 16:12:48 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-mqtt/#7fa219e87b3355e8a6fd281659697fe3a0c87630
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sat Dec 11 16:12:48 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#e4b81f67f939a0c0b11c147ce74aa367271e1279
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 11 16:12:48 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Sat Dec 11 16:12:48 2021 +0000
@@ -0,0 +1,25 @@
+{
+    "config": {
+        "wifi-ssid": {
+            "help": "WIFI SSID",
+            "value": "\"Dobrica's Galaxy A32\""
+        },
+        "wifi-password": {
+            "help": "Wifi Password",
+            "value": "\"mtoy8889\""
+        }
+    },
+    "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