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.

main.cpp

Committer:
wini
Date:
2015-01-02
Revision:
1:734fa1459f69
Parent:
0:bd3aeb15634e
Child:
2:bac2873dbd15

File content as of revision 1:734fa1459f69:


#include "mbed.h"
#include "ledctrl.h"
#include "EthernetInterface.h"

DigitalOut  led1(LED1);
DigitalOut  led2(LED2);
DigitalOut  led3(LED3);
DigitalOut  led4(LED4);

static const LedInfo ledInfo[] = {
   {
      "LED 1",
      LedColor_yellow,
      1
   },
   {
      "LED 2",
      LedColor_red,
      2
   },
   {
      "LED 3",
      LedColor_blue,
      3
   },
   {
      "LED 4",
      LedColor_yellow,
      4
   }
};


extern "C" int
ledState(int ledId, int on, int set)
{
   static int leds[sizeof(ledInfo)/sizeof(ledInfo[1])];
   baAssert(ledId >= 1 && ledId <= sizeof(ledInfo)/sizeof(ledInfo[1]));
   if(set)
      leds[ledId-1] = on;
   return leds[ledId-1];
}


const LedInfo* getLedInfo(int* len)
{
   *len = sizeof(ledInfo) / sizeof(ledInfo[0]);
   return ledInfo;
}

extern "C" const char* getDevName(void)
{
   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)
{
   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;
}


extern "C" int setLedFromDevice(int* ledId, int* on)
{
   return FALSE;
}

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;
   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");
}