Netduino home hardware projects downloads community

Jump to content

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


Member Since 05 Jan 2011
Offline Last Active Aug 30 2015 02:55 PM

Posts I've Made

In Topic: Netduino Firmware v4.1.2 ALPHA 0

20 October 2011 - 06:09 AM

Hi Chris,

I'm really interested in how to create a composite USB device. I mean a mouse and a keyboard emulation with Netduino.
Could you provide a sample please?


Hi FelixEmman,

The UsbClient feature lets you turn your Netduino into a USB device (keyboard, mouse, joystick, or custom). Yes, you could probably turn your Netduino into a Mass Storage Device and access its SD card from a PC--although that may or may not require a little bit of native code as well.

Another nice feature of the Netduino's microcontroller is that it has 5 USB endpoints available. So you could make a "composite" (combination) device. A keyboard + mouse hybrid. Or a CDC serial port + Visual Studio debugging. Or get really creative...


In Topic: Wrong network addressing breaks netduino plus

11 January 2011 - 02:48 PM

I have the same experience, I can see the first ARP request, but no retry (after waiting 30 minutes :) ). A IP stack must retry after a timeout, and after multiple requests it must generate a exception. And it's not the case, like a infinite timeout after the first request. It's probably a bug.


Is it fixed?

In Topic: webservice?

06 January 2011 - 02:05 PM


I used socketclient sample from .Net Microframework SDK to call a web service. There is a better way I'm sure, but I'm newbie and I wanted to port my Arduino code fast.

It works.


using System;
using System.Text;
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 Socket = System.Net.Sockets.Socket;

namespace NetduinoPlus_Temperature_Logger
    public class Program
        static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
        static bool pressing = false;
        static string httpserver = "";
        static Int32 httpport = 81;
        static string SensorID = "000000000000000000000000000000000001";

        public static void Main()
            InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);
            while (true)
                if (!pressing)

        static void button_OnInterrupt(uint data1, uint data2, DateTime time)
            pressing = data2 == 0;
            String request = "POST /SensorService.asmx HTTP/1.1\n";
            request += "Host: " + httpserver + "\n";
            request += "Content-Type: text/xml; charset=utf-8\n";
            request += "Content-Length: 418\n";
            request += "SOAPAction: \"http://" + httpserver + "/StoreData\"\n\n";
            request += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
            request += "<soap:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:soap=\"\">\n";
            request += "<soap:Body>\n";
            request += "<StoreData xmlns=\"http://" + httpserver + "/\">\n";
            request += "<password>upstempdata</password>\n";
            request += "<Value>";
            request += "22.22";
            request += "</Value>\n";
            request += "<SensorID>";
            request += SensorID;
            request += "</SensorID>\n";
            request += "</StoreData>\n";
            request += "</soap:Body>\n";
            request += "</soap:Envelope>\n\n";
                String html = Post(httpserver, httpport, request);
            catch (SocketException se)
                Debug.Print("SocketException when connecting to " + httpserver + ":" + httpport);
                Debug.Print("If your network uses IPSec, you may need enable the port manually");
                Debug.Print("Socket Error Code: " + se.ErrorCode.ToString());

        /// <summary>
        /// Issues a http POST request on the specified server.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="port"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        private static String Post(String server, Int32 port, String request)
            const Int32 c_microsecondsPerSecond = 1000000;

            // Create a socket connection to the specified server and port.
            using (Socket serverSocket = ConnectSocket(server, port))
                // Send request to the server.
                Byte[] bytesToSend = Encoding.UTF8.GetBytes(request);
                serverSocket.Send(bytesToSend, bytesToSend.Length, 0);

                // Reusable buffer for receiving chunks of the document.
                Byte[] buffer = new Byte[1024];

                // Accumulates the received page as it is built from the buffer.
                String page = String.Empty;

                // Wait up to 30 seconds for initial data to be available.  Throws an exception if the connection is closed with no data sent.
                DateTime timeoutAt = DateTime.Now.AddSeconds(30);
                while (serverSocket.Available == 0 && DateTime.Now < timeoutAt)

                // Poll for data until 30-second timeout.  Returns true for data and connection closed.
                while (serverSocket.Poll(30 * c_microsecondsPerSecond, SelectMode.SelectRead))
                    // If there are 0 bytes in the buffer, then the connection is closed, or we have timed out.
                    if (serverSocket.Available == 0) break;

                    // Zero all bytes in the re-usable buffer.
                    Array.Clear(buffer, 0, buffer.Length);

                    // Read a buffer-sized HTML chunk.
                    Int32 bytesRead = serverSocket.Receive(buffer);

                    // Append the chunk to the string.
                    page = page + new String(Encoding.UTF8.GetChars(buffer));

                // Return the complete string.
                return page;

        /// <summary>
        /// Creates a socket and uses the socket to connect to the server's IP address and port.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="port"></param>
        /// <returns></returns>
        private static Socket ConnectSocket(String server, Int32 port)
            // Get server's IP address.
            IPHostEntry hostEntry = Dns.GetHostEntry(server);

            // Create socket and connect to the server's IP address and port
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect(new IPEndPoint(hostEntry.AddressList[0], port));
            return socket;

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.