Connecting to MCSLite

Connecting to MCSLite is very simple if you already know how to connect to MCS. The MCS Library provides a class named MCSLiteDevice, which can be constructed with

MCSLiteDevice(const String& device_id, const String& device_key, const String& server, int port);

The parameters device_id and device_key are exactly the same as their MCSDevice counterparts. You simply have to provide the server address and port of your own MCSLite server. The rest of your program remains the same. In this tutorial, we'll show you how to modify the previous MCS example, LED_control, to the MCSLite version.

Getting MCSLite Server IP and Port

To setup your own MCSLite server, follow these steps:

  1. Download MCSLite according to your platform.

  2. Unzip the downloaded package. It can be under any directory.

  3. Execute the mcs-lite-app executable in the unzipped directory.

Notes for macOS:

Make sure you run the setup script before running mcs-lite-app for the first time. To run the mcs-lite-app, you need to right-click on the app and choose open if you run into the following warning message box:

4. You'll see the IP and Port information in the launched application. This is the server address.

5.You can know use your browser to connect to the IP and port, e.g.

http://172.23.6.42:3000/

6.Now set up your prototypes, channels and devices just like the previous MCS example.

For more information on using MCSLite, visit the MCSLite introduction page.

Using MCSLiteDevice

Now we need to modify the sketch. In your Arduino IDE, select File, then Examples, click MCS then select LED_control.

Find the line MCSDevice, and modify it to MCSLiteDevice, as following:

// Assign device id/key of your test device
// MCSDevice mcs("your_device_id", "your_device_key");
MCSLiteDevice mcs("your_device_id", "your_device_key", "172.23.6.42", 3000);

The IP and port may be different according to your platform, you need to modify it to the same value shown in the mcs-lite-app application.

Now run the sketch as in the previous MCS example. It should work the same as the MCS version.

Last updated