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

MIP tcp/ip stack running on Netduino mini !!


  • Please log in to reply
66 replies to this topic

#61 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 14 April 2014 - 02:04 PM

Great, looking forward too see the vid!

#62 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 22 April 2014 - 04:41 PM

Hi Hanz,

 

I am trying to create an interface between mIP and M2Mqtt, as I understand I need to replace the MqttNetworkChannel with my own implementation that inherits IMqttNetworkChannel and reference my implementation in the MqttClient class. Also I need to replace the dnsLookup in the client class.

 

The IMqttNetworkChannel looks like this:

/// <summary>
    /// Interface for channel under MQTT library
    /// </summary>
    public interface IMqttNetworkChannel
    {
        /// <summary>
        /// Data available on channel
        /// </summary>
        bool DataAvailable { get; }

        /// <summary>
        /// Receive data from the network channel
        /// </summary>
        /// <param name="buffer">Data buffer for receiving data</param>
        /// <returns>Number of bytes received</returns>
        int Receive(byte[] buffer);

        /// <summary>
        /// Send data on the network channel to the broker
        /// </summary>
        /// <param name="buffer">Data buffer to send</param>
        /// <returns>Number of byte sent</returns>
        int Send(byte[] buffer);

        /// <summary>
        /// Close the network channel
        /// </summary>
        void Close();

        /// <summary>
        /// Connect to remote server
        /// </summary>
        void Connect();
    }

Would I be correct in saying that the connect and close methods would come from mIP's Networking class?

 

And Send and Receive from the HttpRequest and HttpResponse classes?

 

I remember reading in the mIP class that it tries to stay away from sockets to make things simpler, would I be right in saying that the mqtt library is using sockets?

 

If so would there be some particular methods I should use instead of the Http ones?

 

Also would you say that Start() in mIP is Connect in M2Mqtt? Stop() relates to Close() ?

 

I have no idea in terms of DataAvailable?

 

Any help would be much appreciated :)

 

Andy



#63 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 04 May 2014 - 06:28 PM

I'm sorry for not being of much help here but I've never dealt with that M2Mqtt.

 

Did you solve the problem eventually?



#64 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 23 June 2014 - 10:09 PM

Hi Hanz,

 

Just wondered if you could give me a few pointers...

 

I am trying to determine what the equivalent mIP method of the following would be:

public int Send(byte[] buffer)
        {
            return this.socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
        } 

And

        public int Receive(byte[] buffer)
        {
            // read all data needed (until the buffer is full)
            int idx = 0;
            while (idx < buffer.Length)
            {
                idx += this.socket.Receive(buffer, idx, buffer.Length - idx, SocketFlags.None);
            }
            return buffer.Length;
        } 

 this.socket.Send is derived from the System.Net.Sockets method:

public int Send(byte[] buffer, int offset, int size, SocketFlags socketFlags);

and this.socket.Receive is from:

public int Receive(byte[] buffer, int offset, int size, SocketFlags socketFlags);

From what I can tell nothing seems to expose a send or receive method that returns a int, my only conclusion would be that this response is returned until the buffer is empty. I guess this would need some adaptation or extension of the mIP methods?

 

 

And finally the only other method I can't work out the mIP equivalent of is as follows, however it may require some extension if its possible:

public bool DataAvailable
{
   get
   {
      return (this.socket.Available > 0);
   }
}

Again drawing from System.Net.Sockets:

public int Available { get; }
 Your guidance would be greatly appreciated :)
 
Many thanks
 
Andy


#65 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 24 June 2014 - 08:59 PM

Hi Hanz,

 

Just a quick update, I have confirmation from Paolo who wrote the M2Mqtt library that the network library in his project uses sockets over tcp. There is a TCP class in the mIP library but I wondered if you or anyone else has any ideas or examples of how to implement TCP sockets with mIP. There are great examples of http and UDP but any pointer as to TCP would be greatly appreciated.

 

I guess in regards to my previous post the questions still remain in terms of extending mIP to provide similar structure to System.Net.Sockets in terms of returning int for send, receive and data available?

 

Thanks as ever,

 

Andy



#66 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 25 June 2014 - 01:44 AM

One of my goals for mIP was to simplify the end-user experience for the typical Connection-less UDP request/response and simple HTTP web requests and HTTP web servers. 

 

To some extent, I was concealing TCP socket access to avoid intimidating users with complex APIs and concepts.  Rest assured that you can still do TCP socket communication, it is just under the covers.  The HTTP implementation uses all TCP communication and is in fact a working example implementation, although not one I'd recommend as a simple example. 

 

In the TCP.cs file, you will find a Connection class.  This is essentially the TCP Socket class.  You can create a new Connection and the Send methods on that class are all TCP Send calls. 

 

The code would look something like this:

<code>

class TcpProgram

{

public static void Main()

{

Networking.Adapter.Start(new byte[] { 0x5c, 0x86, 0x4a, 0x00, 0x00, 0xdd, "mip", InterfaceProfile.NetduinoGo_Socket3_ENC28);

var tcpSocket = new Networking.Connection() { RemoteIP = new byte[] { 192, 168, 0, 1 }, RemotePort = 80 };

tcpSocket.OnConnectionPacketReceived += TcpSocket_OnConnectionPacketReceived;

 

tcpSocket.SendAsync(new byte[] { 1, 2, 3, 4 });  // Send some bytes

 

while (true) Thread.Sleep(100);

 

// When you are done, you can close the socket

tcpSocket.Close();

 

}

 

static void TcpSocket_OnConnectionPacketReceived(Packet thePacket)

{

// A TCP Packet was received.  If the message is long, you will have to piece the packet contents back together to  get the full message. 

 

Debug.Print("New Packet of length: " + thePacket.Content.Length + ", contains: " + thePacket.Content.ToHexString());  // Here is the packet data

 

 

// Note: there are other useful properties on the Packet Class

 

}

}

</code>



#67 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 30 July 2014 - 10:08 PM

Hi Valkyrie

 

Sorry its took so long for me to get back and thanks for the TCP example!

 

The problem I am having is that the M2Mqtt library uses System.Net.Sockets and as I have a very limited understanding of how TCP works I am struggling to identify the parts of mIP I need to use to replace the TCP class (MqttNetworkChannel) in the M2Mqtt project and how to go about implementing them.

 

In your example you clearly show a way of creating a socket, but I don't understand how you achieved this or how it can be extended to cover the scenarios required in the Mqtt TCP class.

 

For example System.Net.Sockets provides:

 

.Send()

.Recieve()

.Available()

.Connect()

.Close()

 

Which are used in the MqttNetworkChannel or TCP class.

 

It also seems that the Send, Receive and Available methods return an int value of the number of bytes sent, left in the buffer or available to be received.

 

What I would like to know is, is there any way I can achieve this with mIP?

 

I would very much like to implement your mIP library with mqtt and appreciate any help you can provide :)

 

Thanks again for your help and I hope with your assistance I can give people using any type of netduino or other boards the ability to use pub sub messaging.

 

Andy






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.