using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
using System.Text;
namespace netduinoplus.app
{
public class Program
{
public static void Main()
{
// create client instance
//MqttClient client = new MqttClient(IPAddress.Parse("iot.eclipse.org"));
//MqttClient client = new MqttClient("85.119.83.194");
//MqttClient client = new MqttClient("dev.rabbitmq.com", 1883, false, null);
MqttClient client = new MqttClient("iot.eclipse.org", 1883, false, null);
// register to message received
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
client.MqttMsgSubscribed += client_MqttMsgSubscribed;
client.MqttMsgUnsubscribed += client_MqttMsgUnsubscribed;
client.MqttMsgPublished += client_MqttMsgPublished;
client.Subscribe(new string[] { "sensor/temp" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
client.Publish("sensor/temp", Encoding.UTF8.GetBytes("10.1"));
var state = client.Connect("netduino_Client", null, null, false, 0, false, null, null, true, 60);
/*
float temp = 80;
while (true)
{
// get temperature value...
temp = temp + 1;
// ...publish it to the broker
client.Publish("sensor/temp", Encoding.UTF8.GetBytes("10.1"));
mqttClient.Publish(MQTT_TEMP_TOPIC, Encoding.UTF8.GetBytes(temp.ToString()));
Thread.Sleep(10000);
}
*/
Thread.Sleep(Timeout.Infinite);
}
public static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
// access data bytes throug e.Message
Debug.Print("Message: " + e.Message);
}
public static void client_MqttMsgUnsubscribed(object sender, MqttMsgUnsubscribedEventArgs e)
{
// write your code
Debug.Print("Unsubscribed ");
}
public static void client_MqttMsgSubscribed(object sender, MqttMsgSubscribedEventArgs e)
{
// write your code
Debug.Print("Subscribed ");
}
public static void client_MqttMsgPublished(object sender, MqttMsgPublishedEventArgs e)
{
// write your code
Debug.Print("Published ");
}
}
}
Ok, I'm making progress. I learned how to include M2Mqtt in the project using NuGet.
I've recoded the netduino piece following Paolo's examples but am having a problem connecting
A number of First Chance exceptions are coming up....
Can someone tell me the secret to getting Paste to work in this box?
Does MQTT work on the NetDuino Plus version 1?
thanks