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

Playing Nim with maths

3 Possible Pitfalls Of Using a Recruitment Agency

Getting Started with Raspberry Pi

Neon EVM Alpha — Now Live on Solana Devnet

How to Upgrade Linux ServeCentOS 7 to CentOS 8

CS371p Spring 2022: David Klingler

Developer Options in Android

HOW-TO: Create a data copy pipeline in Azure Data Factory

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

Using Docker as your production machine with X11

kafkaVision: An open-source monitoring tool for Apache Kafka

Step by Step process to identify Failure modes in distributed systems.

CI for Open Source Dotnet