Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Send data to and recive data from N+2


  • Please log in to reply
19 replies to this topic

#1 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 28 May 2014 - 07:42 PM

Hi,

i would like to send a list of small entitys from my PC to the N+2 (aprox 10 elements)

 

After that, some properties of this entities are updated by sensors.

 

Every 24 hrs i would like to read the updated entitys back to my PC.

 

Any suggestions (WCF,HTTP,MQTT) to handle this Project?

 

Thanks

Peter

.

 



#2 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 28 May 2014 - 08:00 PM

MQTT worked great for me on simple first tries. I ran a broker called mosquito, but I think the M2Mqtt guys have one as well.

 

http://m2mqtt.wordpress.com/

 

Throw in some JSON and it is cakewalk.



#3 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 28 May 2014 - 08:50 PM

Hi,

thanks.

One more question, did MQTT work in two way mode as well?

 

Thanks

Peter



#4 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 29 May 2014 - 04:21 AM

Yes. It is a brokered message passing system. Strikes me as identical to ROS internal stuff.  Clients subscribes to topics, and clients can publish topics. Either side can be a client.  I ran both directions in simple tests, at the same time.  Master asked for an update by publishing a request.  Slave (Netduino) published accelerometer data via a JSON string.  I'm not sure if there was a 'reply' to publish supported, as in a blocking publish, but I don't think you would want that anyhow, on loosely coupled systems.

 

BTW, I was unable to get the micro frameworks supplied DPWS samples (mf version of wcf) to run. It looks like they encountered an error in the MF implementation - multicast udp not supported?.  It seems to me that you should able to get around that not using 'discovery', but I did not want to spend much time on it just to run into the next problem, and no one spoke up and said it would work.  M2Mqtt worked first try, seems to be currently actively maintained, I was impressed.

 

Other projects I ran across had not seen activity in years, and maybe that is because they work and don't need fixing, but that is seldom the case in my experience.  I got the popular web server to run after a few code tweaks, but I would end up just making it look like M2Mqtt anyhow.



#5 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 29 May 2014 - 03:49 PM

Hi,

thanks very much for this detailed explanation.

I will give them a try as soon as possible and will (hopefully *g*) be back

 

Thanks

Peter



#6 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 31 May 2014 - 09:19 PM

http://www.spiked3.com/?p=421

 

has my learning code to date.



#7 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 01 June 2014 - 06:31 PM

Hi,

i will have a look, but this will take a couple of day's because i'm very busy in my main job (roofing and sheetmetal bending)

 

Thanks a lot

Peter



#8 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 04 June 2014 - 06:59 PM

Hi,

i get mqtt from Nuget and write the following snippet:

public static void Main()
        {
            const string brokerIP = "192.168.0.25";
            var x = IPAddress.Parse(brokerIP);
 
            MqttClient client = new MqttClient(IPAddress.Parse(brokerIP));
            client.MqttMsgPublished +=client_MqttMsgPublished;
            client.MqttMsgSubscribed +=client_MqttMsgSubscribed;
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
            string clientId = Guid.NewGuid().ToString();
            Debug.Print("1");
            try
            {
                client.Connect(clientId);
            }
            catch (Exception e)
            {
                Debug.Print(e.InnerException.Message);
                //throw;
            }
            finally
            {
                Debug.Print("finally");
                client.Disconnect();
            }
            
            Debug.Print("2");
            var str = "Hi peter";
 
            for (; ;)
            {
              client.Publish("/home/temperature", Encoding.UTF8.GetBytes(str));  
            }
        }
 
Problem:
after Debug.Print("1")
client.Connect();
i get the following error message:
1
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
A first chance exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException' occurred in M2Mqtt.dll
Exception was thrown: System.Net.Sockets.SocketException
finally
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
A first chance exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException' occurred in M2Mqtt.dll
An unhandled exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException' occurred in M2Mqtt.dll
 Uncaught exception 
The thread '<No Name>' (0x1) has exited with code 0 (0x0).
Done.
 
Any Idea????
Thanks in advance
Peter
 


#9 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 05 June 2014 - 01:16 AM

You will need to look into the socket exception to find the actual win32 socket error. Google that.  I ran into a problem where dhcp had not set the address soon enough - so I finally just started using non-dhcp addresses (I think the error was network down, so it was confusing). 



#10 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 05 June 2014 - 06:18 PM

Hi,

thanks, i will try that.

 

Thanks

Peter



#11 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 05 June 2014 - 08:46 PM

It works.........Thanks.

 

Connecting to the Broker ist working.

 

I create a loop to publish 20 testmessages.

They are published, but never arrive at the Broker.

 

Peter



#12 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 06 June 2014 - 07:23 AM

Which broker are you using?  I grabbed one called mosquito. Not knowing much about them I thought having a python binding would be helpful.  I don't remember having to do anything special to set it up. Just ran the install, and it was an autostarted service. Check to make sure it is running as a service (if you are using mosquito).

 

I just got 2 i2c devices going - and will post that in a new topic in a minute.

 

Had to think about this a little more ....

 

How do you know they are not arriving at the broker?

 

There needs to be a client somewhere subscribing to the topics that will receive them. I'm not sure I really see any activity on the broker - actually its a service with no console or UI, so I'm sure I don't see anything there :)



#13 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 06 June 2014 - 07:00 PM

Hi,

i'm using http://mqttbroker.codeplex.com/

this seems to be the 'brother' of http://m2mqtt.codeplex.com/

I set Debug.Print statements in some(all) the EventHandlers in the broker, and only one of them (Client.Connected) is called.

I also can see that my client is added to the Client-Collection.

 

I think i will give mosquito a try.

 

Thanks

Peter



#14 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 06 June 2014 - 07:03 PM

Sure sounds like it should see the publish messages, but you sound like you are on the right track. Let us know how it goes.



#15 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 06 June 2014 - 08:42 PM

Hi,

i install  mosquito, start, worked as far as i can see (Pub + Sub are in the same app)

 

Now i will try and build a publisher on the N2+ and a subscriber on my pc.

i will by back and Report my success*g*

 

Peter



#16 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 08 June 2014 - 07:56 PM

Hi,

communication with mosquito from N2+ to my Laptop and back works excellent.i wonder why i have problems with the Broker from codeplex.

By the way, did you have tryed 2-way communication?

 

Thanks a lot

 

Peter



#17 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 09 June 2014 - 12:11 AM

No, I haven't - other than the loosely coupled idea; send a request, send a reply.

Is there something explicitly 2-way?  I'll have to look.

 

Glad it is working. It worked well for me without much effort also. I plan on using it as a main component of my learning robot project, knowing that if I swap a piece later (the main processor or netduino I/O), i will not have to re-write everything.

 

CAD files sent to be cut this week :)  http://www.spiked3.com/?p=338



#18 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 09 June 2014 - 08:50 AM

Hi,

and good morning(in Germany) .

Yes, i made 2-way communication with sending Messages for and back under two Topics.

If i find a better way, i let you know.

 

Great CAD Files, These stuff is much more closer to my job as writing Software.

 

Now, as i have seen thes the communication is working i have work some days on my second project:

 

http://www.icsharpco...SD/Default.aspx

https://github.com/i...pReporting/wiki

 

Peter

 



#19 Peter Forstmeier

Peter Forstmeier

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 09 June 2014 - 05:34 PM

Hi again,

i stay in contact with the author of mqttbroker. He told me to use short Clientid's like 'textclient' or similar, and now it's working.

 

Peter



#20 Paolo Patierno

Paolo Patierno

    Advanced Member

  • Members
  • PipPipPip
  • 169 posts
  • LocationItaly

Posted 22 September 2014 - 08:31 PM

Hi,

the M2Mqtt client and related GnatMQ broker are compliant with actual MQTT specification that limits client id to 23 characters.

This limitation was removed in 3.1.1 specification that isn't standard yet. When it will become standard, I will change library to support it.

 

Paolo.


Paolo Patierno

Microsoft MVP on Windows Embedded & IoT

Azure Advisor

Twitter : @ppatierno
Linkedin : paolopatierno
Blog : DevExperience

Blog : Embedded101
?





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.