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
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
- SharkMQ (Secure) Client Example
- SMQ LED Demonstration Tutorial
- SMQ Documentation
- Real Time Logic LLC public SMQ Broker access.
- How to set up your own low cost SMQ Broker cloud server solution Tutorial.
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.
Diff: main.cpp
- Revision:
- 2:bac2873dbd15
- Parent:
- 1:734fa1459f69
--- a/main.cpp Fri Jan 02 20:27:26 2015 +0000 +++ b/main.cpp Fri Mar 25 23:07:22 2016 +0000 @@ -31,24 +31,37 @@ } }; +static int leds[sizeof(ledInfo)/sizeof(ledInfo[1])]; -extern "C" int -ledState(int ledId, int on, int set) +/* Returns the LED on/off state for led with ID 'ledId'. +*/ +int getLedState(int ledId) { - 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]; } +/* + Return an array of LedInfo (struct). Each element in the array + provides information for one LED. The 'len' argument must be set by + function getLedInfo. The out argument 'en' specifies the length of + the returned array, that is, number of LEDs in the device. Each LED + has a name, color, and ID. The ID, which provides information about + which LED to turn on/off, is used by control messages sent between + device code and UI clients. The IDs for a four LED device can for + example be 1,2,3,4. +*/ const LedInfo* getLedInfo(int* len) { *len = sizeof(ledInfo) / sizeof(ledInfo[0]); return ledInfo; } + +/* Returns the name of this device. The name is presented by UI + clients such as browsers. + */ extern "C" const char* getDevName(void) { return "mbed: Arch Pro"; @@ -83,10 +96,14 @@ } } +/* Command sent by UI client to turn LED with ID on or off. This + function must set the LED to on if 'on' is TRUE and off if 'on' is FALSE. + */ extern "C" int setLed(int ledId, int on) { - ledState(ledId, on, TRUE); - on = on ? 0 : 1; + baAssert(ledId >= 1 && ledId <= sizeof(ledInfo)/sizeof(ledInfo[1])); + leds[ledId-1] = on; + on = on ? 0 : 1; /* Invert */ switch(ledId) { case 1: led1 = on; break; @@ -98,6 +115,19 @@ } +/* + An optional function that enables LEDs to be set directly by the + device. This function is typically used by devices that include one + or more buttons. A button click may for example turn on a specific + LED. The function is called at intervals (polled) by the LED device + code. The function may for example detect a button click and return + the information to the caller. Arguments 'ledId' and 'on' are out + arguments, where 'ledId' is set to the LED ID and 'on' is set to + TRUE for on and FALSE for off. The function must return TRUE (a non + zero value) if the LED is to be set on/off and zero on no + change. Create an empty function returning zero if you do not plan + on implementing this feature. +*/ extern "C" int setLedFromDevice(int* ledId, int* on) { return FALSE; @@ -161,22 +191,30 @@ } } -extern "C" { - int smqUniqueIdLen; - const char* smqUniqueId; + +static EthernetInterface eth; + + +/* Required by SMQ examples. + The unique ID is used when calling the SMQ constructor. The + unique ID is typically set to the MAC address. See the SMQ + documentation for details: + https://realtimelogic.com/ba/doc/en/C/shark/structSharkMQ.html +*/ +int getUniqueId(const char** id) +{ + *id=eth.getMACAddress(); + return strlen(*id); } 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"); }