[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[paho-dev] case study using M2Mqtt C# example develing with SharpDevelop - information about C# dotnet MQTT Client Library Encyclopedia – M2Mqtt
|
A kindly request to this group: is there somebody available with C#
knowledge of the M2Mqtt library and who can answer my questions, which I
sent last week to this group?
At present I could build and run the prototype C# program without
runtime errors, but I get a MSgID of value 1 and my Groovy subscriber
did not recieve the topic and Payload message.
What does the value 1 of the MsgID means?
With best regards,
Jan Willem
------------------------------ previous email ----------------
Hallo Paolo and pah-dev group,
On March, the 29th I sent you, Paolo, an email with some questions about
C# M2Mqtt client library in order to make a start with a case study on
the subject of using the M2Mqtt library in a Winbatch script on a
Windows 10 pro (64) environment. A couple days later I also joined the
paho-dev mailing group following an advice form Dominik of HiveMQ.
unfortunately I did not get any answers on both emails.
In the meantime I started to develop as a first step a sample C# program
in order to get familiar with the library in publishing a payload
message, see the attached program.cs file.
When I build the program.cs in sharpDeveloper, I get the following
errors, which are in Dutch.
<code>
Build started.
Warning MSB3247: conflicten gevonden tussen verschillende versies van
dezelfde afhankelijke assembly.
Compiling m2mqttPubMsg
D:\Ontwikkelomgeving\C#_mono\m2mqttPubMsg\m2mqttPubMsg\Program.cs(48,4)
: Error CS0012: Het type System.Object wordt gedefinieerd in een
assembly waarnaar niet wordt verwezen. U moet een verwijzing naar de
assembly System.Runtime, Version=4.0.10.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a toevoegen.
D:\Ontwikkelomgeving\C#_mono\m2mqttPubMsg\m2mqttPubMsg\Program.cs(53,4)
: Error CS0012: Het type System.MulticastDelegate wordt gedefinieerd in
een assembly waarnaar niet wordt verwezen. U moet een verwijzing naar de
assembly System.Runtime, Version=4.0.10.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a toevoegen.
D:\Ontwikkelomgeving\C#_mono\m2mqttPubMsg\m2mqttPubMsg\Program.cs(53,31)
: Error CS0103: De naam client_MqttMsgPublished bestaat niet in de
huidige context
D:\Ontwikkelomgeving\C#_mono\m2mqttPubMsg\m2mqttPubMsg\Program.cs(56,31)
: Error CS0103: De naam MqttMsgBase bestaat niet in de huidige context
Build failed. (00:00:00.7828545)
</code>
The warning is about differences in reference to the used assemblies in
M2Mqtt.WinRT.dll. The tool AsmSpy gives the differences as:
<code>
Reference: System.Runtime
4.0.10.0 by M2Mqtt.WinRT
4.0.0.0 by M2Mqtt.WinRT
Reference: System.Collections
4.0.0.0 by M2Mqtt.WinRT
Reference: System.Threading
4.0.0.0 by M2Mqtt.WinRT
Reference: Windows
255.255.255.255 by M2Mqtt.WinRT
Reference: System.Text.Encoding
4.0.0.0 by M2Mqtt.WinRT
Reference: System.Runtime.Extensions
4.0.0.0 by M2Mqtt.WinRT
Reference: System.Threading.Tasks
4.0.0.0 by M2Mqtt.WinRT
Reference: System.Runtime.WindowsRuntime
4.0.10.0 by M2Mqtt.WinRT
</code>
How can I resolve this warning and the related errors?
Any tips or suggestions?
Thanks in advance,
Beste regards, from the Netherlands,
Jan Willem Teunisse
------------------- previous email29-3-2016 ------------------
Ciao Paolo,
Last week I read your nice and clear article about the MQTT Client
library (M2Mqtt) and liked to try it for my domotica IoT project.
I installed yesterday using Nuget the M2Mqtt dotnet library package on
my windows10 development PC in order to publish a MQTT message using a
Winbatch script.
Winbatch support dotnet assemblies. The M2Mqtt package is installed in
the Winbatch script directory using “nuget install M2Mqtt -o
D:\Winbatch\Ontw”
After installing the M2Mqtt package I saw 6 subdirectories in the
d:\Winbatch\Ontw\M2Mqtt.4.3.0.0\lib\ directory. All containing different
DLLs.
I’m now confused which DLL I have to take to get the
uPLibrary.Networking.M2Mqtt namespace and to define the object new
MqttClient.
Maybe you can help me out, as I need some suggestions or advice to
proceed from here on to get things working.
Beste regards, from the Netherlands,
Jan Willem Teunisse
P.S. I also posted a comment on the blog of the above mentioned article,
Dominik advices me to contact you more or less directly.
/*
* Created by SharpDevelop.
* User: JWT_Kantoor
* Date: 5-4-2016
* Version: 0.0.1
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
// using System.MulticastDelegate;
// using System.Object;
// using System.Runtime;
// 4.0.10.0 by M2Mqtt.WinRT
// 4.0.0.0 by M2Mqtt.WinRT
// using System.Collections;
// 4.0.0.0 by M2Mqtt.WinRT
//using System.Threading;
// 4.0.0.0 by M2Mqtt.WinRT
// using Windows ;
// 255.255.255.255 by M2Mqtt.WinRT
using System.Text; //.Encoding;
// 4.0.0.0 by M2Mqtt.WinRT
// using System.Runtime.Extensions;
// 4.0.0.0 by M2Mqtt.WinRT
// using System.Threading.Tasks;
// 4.0.0.0 by M2Mqtt.WinRT
// using System.Runtime; // .WindowsRuntime;
// 4.0.10.0 by M2Mqtt.WinRT
using uPLibrary.Networking.M2Mqtt;
namespace m2mqttPubMsg
{
public class Program
{
public static void Main(string[] args)
{
string MQTT_ADDRESS = "192.168.10.22" ;
string MQTT_PORT = "1883" ;
string MQTT_URL ;
string MQTT_Client_ID = "mqttC#PubMsg";
string MQTT_TOPIC = "micasa/sunctrlr/stat/status" ;
string MQTT_PAYLOAD ;
Console.WriteLine("Start publish MQTT Topic and Payload messages:");
MQTT_URL = MQTT_ADDRESS + ":" + MQTT_PORT ;
Console.WriteLine("MQTT_URL: "+ MQTT_URL);
// TODO: Implement Functionality Here
MqttClient client = new MqttClient(MQTT_URL);
byte code = client.Connect(MQTT_Client_ID);
// client.ProtocolVersion = MqttProtocolVersion.Version_3_1; // uitgezet
// set PAYLOAD Message
MQTT_PAYLOAD = "RolledIn;20160406T17:00" ;
client.MqttMsgPublished += client_MqttMsgPublished;
ushort msgId = client.Publish(MQTT_TOPIC, // topic
Encoding.UTF8.GetBytes(MQTT_PAYLOAD), // message body
MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, // QoS level
false); // retained
client.Disconnect();
Console.WriteLine("Message ID = {0}", msgId);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}