MQTT client to test the ENC28J60-EMAC on NUCLEO-L152RE

Dependencies:   ENC28J60-EMAC

Revision:
6:c123d9b8e6f4
Parent:
5:d9570dbf2f82
--- a/main.cpp	Mon Mar 29 09:32:44 2021 +0000
+++ b/main.cpp	Fri Aug 20 11:02:55 2021 +0000
@@ -1,3 +1,4 @@
+//based on MQTT-Hello from Zoltan Hudak
 #include "mbed.h"
 
 #include "EthernetInterface.h"
@@ -8,7 +9,7 @@
 #define IP          "192.168.1.35"
 #define GATEWAY     "192.168.1.1"
 #define NETMASK     "255.255.255.0"
-#define BROKER_IP   "192.168.1.31"  // IP address of your MQTT broker. Change to match your case.
+#define BROKER_IP   "192.168.1.106"  // IP address of your MQTT broker. Change to match your case.
 #define MQTT_PORT   1883            // MQTT port
 
 const uint8_t                           MAC[6] = { 0, 1, 2, 3, 4, 5 };
@@ -20,6 +21,7 @@
 MQTTNetwork                             mqttNetwork(&net);
 MQTT::Client<MQTTNetwork, Countdown>    mqttClient(mqttNetwork);
 Timer                                   timer;
+Thread thread;
 
 // Function prototypes
 void                                    onMqttMsgReceived(MQTT::MessageData& md);
@@ -43,6 +45,11 @@
  * @param
  * @retval
  */
+ void check()
+{
+     while(1) mqttClient.yield(10);
+}
+ 
 int main(void)
 {
     // Bring up the ethernet interface
@@ -92,14 +99,15 @@
 
     // Start timer
     timer.start();
-    
+    thread.start(&check);
     // Main thread loop
     while (1) {
-        mqttClient.yield(10);
-        if (timer.read_ms() > 1000) {
-            timer.reset();
+//        mqttClient.yield(10);
+//        if (timer.read_ms() > 1000) {
+//            timer.reset();
             publishMsg();   // once a second publish the MQTT message
-        }
+            HAL_Delay(1000);
+//        }
     }
 }