Example program that shows how to use the Secure (TLS) SharkMQ library included in SharkSSL-Lite

Dependencies:   EthernetInterface SharkSSL-Lite mbed-rtos mbed

Introduction

The SMQ Architecture is an Internet of Things (IoT) publish subscribe end-to-end solution that is optimized for embedded systems to provide instantaneous Device Edge Node connectivity, 1 to 1 Communications, and Ease of Transcending Firewalls. The solution is ideal for resource constrained devices that require real-time dynamic control, analytic information, and firmware updates in both LAN and WAN environments.

Architecture Component List

  • SMQ C Client (Non-secure)
  • SharkMQ Secure C Client (this mbed example)
  • SMQjs (Javascript)
  • SMQ JAVA
  • SMQ Broker

/media/uploads/wini/smq_architecture.png

SharkMQ-LED-Demo

An example of (Secure) device control via a Browser interface. It includes the LED demonstration example code, SharkMQ, and SharkSSL SSL|TLS stack for authentication and encryption.

Video Tutorials

How to setup your own secure SMQ IoT cloud server

Most IoT cloud server solutions, whether they provide ready-to-use hosted services or not, are based on a standard Virtual Private Server (VPS). Most developers probably think of Amazon or Microsoft Azure's services when considering the server side of their IoT solution. These high-end services are great if you need to scale up to millions of connected devices. However, for most small-scale operations and DIY projects, a low-cost VPS is more than adequate.

SMQ LED Demo

See Also

Revision:
1:7099d4432b41
Parent:
0:10b4212318d4
Child:
2:fd1c5fac2380
--- a/main.cpp	Wed Apr 06 01:19:36 2016 +0000
+++ b/main.cpp	Fri Apr 08 15:28:51 2016 +0000
@@ -1,4 +1,3 @@
-
 #include "mbed.h"
 #include "ledctrl.h"
 #include "EthernetInterface.h"
@@ -31,14 +30,17 @@
    }
 };
 
-static int leds[sizeof(ledInfo)/sizeof(ledInfo[1])];
+#define LEDSLEN (sizeof(ledInfo) / sizeof(ledInfo[0]))
+
+static int leds[LEDSLEN];
 
 /* Returns the LED on/off state for led with ID 'ledId'.
 */
 int getLedState(int ledId)
 {
-   baAssert(ledId >= 1 && ledId <= sizeof(ledInfo)/sizeof(ledInfo[1]));
-   return leds[ledId-1];
+   if(ledId >= 1 && ledId <= LEDSLEN)
+      return leds[ledId-1];
+   return 0;
 }
 
 
@@ -54,7 +56,7 @@
 */
 const LedInfo* getLedInfo(int* len)
 {
-   *len = sizeof(ledInfo) / sizeof(ledInfo[0]);
+   *len = LEDSLEN;
    return ledInfo;
 }
 
@@ -64,21 +66,21 @@
  */
 extern "C" const char* getDevName(void)
 {
-   return "mbed: Arch Pro";
+   return "mbed: Arch Pro : SharkSSL-Lite";
 }
 
 static void blinkAll(int fast)
 {
    int i;
-   for(i = 1 ; i <= 4 ; i++) setLed(i, FALSE);
-   for(i = 1 ; i <= 4 ; i++)
+   for(i = 0 ; i < LEDSLEN ; i++) setLed(ledInfo[i].id, FALSE);
+   for(i = 0 ; i < LEDSLEN ; i++)
    {
-      setLed(i, TRUE);
+      setLed(ledInfo[i].id, TRUE);
       wait_ms(fast ? 120: 400);
    }
-   for(i = 1 ; i <= 4 ; i++)
+   for(i = 0 ; i < LEDSLEN ; i++)
    {
-      setLed(i, FALSE);
+      setLed(ledInfo[i].id, FALSE);
       wait_ms(fast ? 120: 400);
    }
 }
@@ -101,17 +103,20 @@
  */
 extern "C" int setLed(int ledId, int on)
 {
-   baAssert(ledId >= 1 && ledId <= sizeof(ledInfo)/sizeof(ledInfo[1]));
-   leds[ledId-1] = on;
-   on = on ? 0 : 1; /* Invert */
-   switch(ledId)
+   if(ledId >= 1 && ledId <= LEDSLEN)
    {
-      case 1: led1 = on; break;
-      case 2: led2 = on; break;
-      case 3: led3 = on; break;
-      case 4: led4 = on; break;
+      leds[ledId-1] = on;
+      on = on ? 0 : 1; /* Invert */
+      switch(ledId)
+      {
+         case 1: led1 = on; break;
+         case 2: led2 = on; break;
+         case 3: led3 = on; break;
+         case 4: led4 = on; break;
+      }
+      return 0;
    }
-   return 0;
+   return -1;
 }
 
 
@@ -135,8 +140,8 @@
 
 extern "C" void setProgramStatus(ProgramStatus s)
 {
-       int i;
-   for(i = 1 ; i <= 4 ; i++) setLed(i, FALSE);
+   int i;
+   for(i = 0 ; i < LEDSLEN ; i++) setLed(ledInfo[i].id, FALSE);
    switch(s)
    {
       case ProgramStatus_Restarting:
@@ -146,21 +151,21 @@
          break;
 
       case ProgramStatus_Connecting:
-         setLed(1, TRUE);
+         setLed(ledInfo[1].id, TRUE);
          break;
 
       case ProgramStatus_SslHandshake:
-         setLed(2, TRUE);
+         setLed(ledInfo[2].id, TRUE);
          break;
 
       case ProgramStatus_DeviceReady:
-         for(i = 1 ; i <= 4 ; i++) setLed(i, TRUE);
+         for(i = 0 ; i < LEDSLEN ; i++) setLed(ledInfo[i].id, TRUE);
          wait(1);
-         for(i = 1 ; i <= 4 ; i++) setLed(i, FALSE);
+         for(i = 0 ; i < LEDSLEN ; i++) setLed(ledInfo[i].id, FALSE);
          break;
 
       case ProgramStatus_CloseCommandReceived:
-         blink(3);
+         blink(ledInfo[3].id);
          break;
 
       default:
@@ -172,20 +177,20 @@
             case ProgramStatus_WebServiceNotAvailError:
             case ProgramStatus_InvalidCommandError:
             case ProgramStatus_PongResponseError:
-               blink(1);
+               blink(ledInfo[1].id);
                break;
 
             case ProgramStatus_ConnectionError:
-               blink(2);
+               blink(ledInfo[2].id);
                break;
 
             case ProgramStatus_CertificateNotTrustedError:
             case ProgramStatus_SslHandshakeError:
-               blink(3);
+               blink(ledInfo[3].id);
                break;
 
             case ProgramStatus_MemoryError:
-               for(i = 1 ; i <= 4 ; i++) blink(i);
+               for(i = 0 ; i < LEDSLEN ; i++) blink(ledInfo[i].id);
                break;
          }
    }