SMQ is an easy to use machine-to-machine (M2M)/"Internet of Things" connectivity protocol that follows the publish subscribe design pattern.

Dependencies:   EthernetInterface 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
  • SMQjs (Javascript)
  • SMQ JAVA
  • SMQ Broker

/media/uploads/wini/smq_architecture.png

SMQ Client-example

A (non-secure) C Client implementation of the SMQ protocol demonstrating device control over the on board LEDs via any modern (WebSocket enabled) Browser interface.

  • Code Size: 3kB

See Also

How to setup your own 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.

Revision:
1:734fa1459f69
Parent:
0:bd3aeb15634e
Child:
2:bac2873dbd15
--- a/main.cpp	Wed Dec 03 23:54:54 2014 +0000
+++ b/main.cpp	Fri Jan 02 20:27:26 2015 +0000
@@ -4,16 +4,30 @@
 #include "EthernetInterface.h"
 
 DigitalOut  led1(LED1);
-
-//PATCH CTX
-extern "C" void mainTask(const char* uuid, int uuidLen, const char* devInfo);
-
+DigitalOut  led2(LED2);
+DigitalOut  led3(LED3);
+DigitalOut  led4(LED4);
 
 static const LedInfo ledInfo[] = {
    {
       "LED 1",
-      LedColor_green,
+      LedColor_yellow,
       1
+   },
+   {
+      "LED 2",
+      LedColor_red,
+      2
+   },
+   {
+      "LED 3",
+      LedColor_blue,
+      3
+   },
+   {
+      "LED 4",
+      LedColor_yellow,
+      4
    }
 };
 
@@ -40,10 +54,46 @@
    return "mbed: Arch Pro";
 }
 
+static void blinkAll(int fast)
+{
+   int i;
+   for(i = 1 ; i <= 4 ; i++) setLed(i, FALSE);
+   for(i = 1 ; i <= 4 ; i++)
+   {
+      setLed(i, TRUE);
+      wait_ms(fast ? 120: 400);
+   }
+   for(i = 1 ; i <= 4 ; i++)
+   {
+      setLed(i, FALSE);
+      wait_ms(fast ? 120: 400);
+   }
+}
+
+
+static void blink(int led)
+{
+   int i;
+   for(i = 0 ; i < 30; i++)
+   {
+      setLed(led, 1);
+      wait_ms(120);
+      setLed(led, 0);
+      wait_ms(120);
+   }
+}
+
 extern "C" int setLed(int ledId, int on)
 {
-   led1 = on;
    ledState(ledId, on, TRUE);
+   on = on ? 0 : 1;
+   switch(ledId)
+   {
+      case 1: led1 = on; break;
+      case 2: led2 = on; break;
+      case 3: led3 = on; break;
+      case 4: led4 = on; break;
+   }
    return 0;
 }
 
@@ -55,12 +105,78 @@
 
 extern "C" void setProgramStatus(ProgramStatus s)
 {
+       int i;
+   for(i = 1 ; i <= 4 ; i++) setLed(i, FALSE);
+   switch(s)
+   {
+      case ProgramStatus_Restarting:
+         blinkAll(FALSE);
+      case ProgramStatus_Starting:
+         blinkAll(TRUE);
+         break;
+
+      case ProgramStatus_Connecting:
+         setLed(1, TRUE);
+         break;
+
+      case ProgramStatus_SslHandshake:
+         setLed(2, TRUE);
+         break;
+
+      case ProgramStatus_DeviceReady:
+         for(i = 1 ; i <= 4 ; i++) setLed(i, TRUE);
+         wait(1);
+         for(i = 1 ; i <= 4 ; i++) setLed(i, FALSE);
+         break;
+
+      case ProgramStatus_CloseCommandReceived:
+         blink(3);
+         break;
+
+      default:
+         blinkAll(FALSE);
+         switch(s)
+         {
+            case ProgramStatus_SocketError:
+            case ProgramStatus_DnsError:
+            case ProgramStatus_WebServiceNotAvailError:
+            case ProgramStatus_InvalidCommandError:
+            case ProgramStatus_PongResponseError:
+               blink(1);
+               break;
+
+            case ProgramStatus_ConnectionError:
+               blink(2);
+               break;
+
+            case ProgramStatus_CertificateNotTrustedError:
+            case ProgramStatus_SslHandshakeError:
+               blink(3);
+               break;
+
+            case ProgramStatus_MemoryError:
+               for(i = 1 ; i <= 4 ; i++) blink(i);
+               break;
+         }
+   }
 }
 
+extern "C" {
+    int smqUniqueIdLen;
+    const char* smqUniqueId;
+}
 
 int main()
 {
    EthernetInterface eth;
-   mainTask(eth.getMACAddress(), strlen(eth.getMACAddress()), getDevName());
+   xprintf(("\n\n\nIn main\n"));
+   eth.init(); //Use DHCP
+   xprintf(("EthernetInterface connect\n"));
+   blinkAll(FALSE);
+   eth.connect();
+   xprintf(("IP Address is %s\n", eth.getIPAddress()));
+   smqUniqueId = eth.getMACAddress();
+   smqUniqueIdLen = strlen(smqUniqueId);
+   mainTask(0);
    error("mainTask returned");
 }