Connecting .NET Gadgeteer to the Alibaba Cloud IoT Platform Using C#

  1. The USB device module is plugged in to the 2# interface
  2. The DHT11 module is plugged in to the 14# interface
  3. The LED module is plugged in to the 12# interface
  4. The Ethernet module is plugged in to the 4# interface

Step 1: Set Up Alibaba Cloud IoT Platform

Step 2: Implement Alink Protocol

byte[] bytData = new byte[4];
float T = 0;
float H = 0;
int ret = gs.IOControl((int)(6*16+11)); //PG11
if (ret ! = -1)
{
bytData[0] = (byte)(ret & 0xFF);
bytData[1] = (byte)(ret >> 8 & 0xFF);
bytData[2] = (byte)(ret >> 16 & 0xFF);
bytData[3] = (byte)(ret >> 24 & 0xFF);

H = Byte2Float(bytData[0], bytData[1]);
T = Byte2Float(bytData[2], bytData[3]);
Debug.Print("H = " + H.ToString() + " T = " + T.ToString());

string payload_json = "{" +
"\"id\": " + DateTime.Now.Ticks + "," +
"\"params\":{" +
"\"temperature\":" + T + "," +
"\"humidity\":" + H + "," +
"}," +
"\"method\":\"thing.event.property.post\"" +
"}";
string Data = Guid.NewGuid(). ToString();
mqttClient.Publish(post_topic, Encoding.UTF8. GetBytes(payload_json), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);
Debug.Print(payload_json);
}
{"method":"thing.service.property.set","id":"196011725","params":{"LED":1},"version":"1.0.0"}
OutputPort led = new OutputPort((Cpu.Pin)(7*16+9),false);
string json = "";
if (e.Message.Length > 0)
{
//{"method":"thing.service.property.set","id":"196011725","params":{"LED":1},"version":"1.0.0"}
json = new string(System.Text.UTF8Encoding.UTF8. GetChars(e.Message));
Debug.Print("Message:" + json);

string strLED =json.Substring(json.IndexOf("LED")+5,1);
led.Write((strLED == "1"));
}

Step 3: Run the Code

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The difference between Expression and Statement

Debugging Hell, The A-HA Moment

What Does 5G Do for Edge Computing?

[a4asset] Product roadmap

CS371p Fall 2020: Jaden Hyde

Build an SMS Hub in Under 7 Minutes with Twilio, Standard Library and Node.js

7 Factors that Influence UnixBench Scores

Getting started with the VideoCoin Publisher Studio

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

The idea behind Docker and Linux containers

Introduction to Routing with Apache Camel

How we implemented Pod Logging at NetBook

Most important metric for operating Elasticsearch