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

Help with netduino Networking


  • Please log in to reply
9 replies to this topic

#1 HAYwired

HAYwired

    New Member

  • Members
  • Pip
  • 2 posts

Posted 22 March 2014 - 07:20 PM

HI all, i am from Bloemfontein South Africa and i study computer engineering here, we use the Netduino Plus 2 in programming and my group is having a bit of trouble with our latest assignment so i hope you guys can help.

 

The Assignment:

 

A temperature logging and analysis system using Netduino.

Your Group is to create a TCP/IP based network server application that will run on a Netduino Plus 2.
The server application must allow a minimum of 3 client connections. Once a client is connected the server application transmits the information from several temperature sensors to the client, at a rate that the client specifies. E.g. if the client want the data every 5min the server should only send it once every 5min.

You should also create a client application (that runs on a PC) that is able to connect to the server, receive the temperature data, and save it to a file with a timestamp. Your client should have an option to read the data file and visually display the change in temperature over time in some way or another. The client should also have the means to configure some basic network settings.

 

The Problem:

 

We have created bot the server and the client and everything connects like it should the problem we have is that we have no idea how to send and recieve the data from the netduino to the client aplication.

 

Thanks in advance.



#2 knut.tveitane

knut.tveitane

    Member

  • Members
  • PipPip
  • 18 posts

Posted 23 March 2014 - 06:15 AM

Hi,

 

I will give you a hint:

 

It is not so strange that you don't know how to send and receive data from the server to the client - because this is not possible. It is the client that sends and requests data to/from the server, using HTTP requests. The server listens for requests from clients, and responds to them.



#3 wendo

wendo

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 23 March 2014 - 07:04 AM

There isn't any reason it has to be HTTP. Running a full web server for something like this actually seems like overkill. A simple command based protocol like telnet may be much easier especially since there is no binary data that needs to be sent



#4 knut.tveitane

knut.tveitane

    Member

  • Members
  • PipPip
  • 18 posts

Posted 23 March 2014 - 08:48 AM

You are completely right of course - any TCP/IP-based protocol will do, according to the assignment. But even with Telnet the client has to initiate the queries.



#5 HAYwired

HAYwired

    New Member

  • Members
  • Pip
  • 2 posts

Posted 24 March 2014 - 05:44 AM

Thanks guys we have managed to get the network to send and receive data from each other, getting a different problem but i will ask about that a bit later today if we dont come right.



#6 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 01 April 2014 - 01:19 PM

Thanks guys we have managed to get the network to send and receive data from each other, getting a different problem but i will ask about that a bit later today if we dont come right.

 

I've managed HTTP communication from client(PC) to server(NP2) using a (small) web server that runs on my NP2. However the client, which is a pc application, immediatly gets a connection closed exception. You have any idea why this might occur? 

 

Project link: https://netduinoblog...an-you-hear-me/



#7 jrlyman3

jrlyman3

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts
  • LocationNorth St Paul. MN

Posted 01 April 2014 - 02:22 PM

I'm guessing that your NP2 server code is closing the socket after it sends the HTTP reponse.



#8 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 06 April 2014 - 06:47 AM

I'm guessing that your NP2 server code is closing the socket after it sends the HTTP reponse.

In that case my response object would have been filled just before the connection closed exception occured, no? It now breaks when trying to fill that object. 



#9 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 11 April 2014 - 10:45 AM

So I've been analysing the webserver code. 

 

Webserver Start

public WebServerController(int port, int timeout)
        {
            this.Timeout = timeout;
            this.Port = port;
            this.serverThread = new Thread(StartServer);
            Debug.Print("Web server started on port " + port.ToString());
            this.CommandReceived += WebServerController_CommandReceived;
           // _temperatureController = new OneWireTemperatureSensorController(Pins.GPIO_PIN_D0);


        }

CommandHandling & Send Response

void WebServerController_CommandReceived(object obj, WebServerEventArgs e)
        {

Outputstream(e.response,"OK");
}


public static string OutPutStream(Socket response, string strResponse)
        {
            try
            {
                byte[] messageBody = Encoding.UTF8.GetBytes(strResponse);
                if (!response.Poll(0, SelectMode.SelectError))
                if (response != null)
                {
                    Debug.Print("Sending Response! ( " + messageBody.Length + ") " + response +" " + messageBody);
                    response.Send(messageBody, 0, messageBody.Length, SocketFlags.None);
                }
                //allow time to physically send the bits
                Thread.Sleep(1000);
                return "";
            }
            catch (Exception ex)
            {


                Debug.Print("Error while sending reply  " + ex.Message);
                return ex.Message;
            }
           
        }

My PC Client sending the command receives a webexception (connection closed). I believe it may be because the Netduino Webserver response doesn't contain HTTP Headers, which is a HTTP Violation thus the error. Or would that result in a different exception?

They debate about the same thing here: http://stackoverflow...-httpwebrequest

 

Any suggestions or ideas I could try?  



#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 11 April 2014 - 12:10 PM

My PC Client sending the command receives a webexception (connection closed). I believe it may be because the Netduino Webserver response doesn't contain HTTP Headers, which is a HTTP Violation thus the error. Or would that result in a different exception?

Very interesting. Do you have more info on this (differences in HTTP headers between .NETMF and .NET) that create a potential HTTP compliance issue? If there's a bug there we'd love to dig in and fix it.

Thank you,

Chris




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.