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

Beginner Question and Hello!


  • Please log in to reply
11 replies to this topic

#1 PawleysPlayr

PawleysPlayr

    Member

  • Members
  • PipPip
  • 11 posts

Posted 27 April 2011 - 03:04 PM

First off hello all! Great forum you guys have here. A little background: I'm not a programmer by trade, but have written some VB.Net winforms apps reading serial devices etc. On the electronics front, I can use a meter and have a comfortable relationship with a breadboard. I've got my Net+, done the simple LED/Button/Voltage Divider projects. Mostly have a handle on the basics of these. So, to help me out you might need to "dumb down" your answers a little more than you are used to. ;) I make beer. My project goal is connect 6 thermistors to the Net+ and map the temperature profile in my mash tun throughout a mash. An app running on my PC would connect to the Net+ vis ethernet and collect that temperature data to trend/log/whatever. The main point being a learning Net+ project that provides some useful results. That ethernet connection (sockets I guess) is where I need some patient help. I ran the webserverhello world example and that was pretty cool, but that really doesn't fit my project. Maybe there is already an example of how to do this here, but everything I've found so far seems to be interested in http only. Maybe that will be a next step for me, but right now I'm having enough trouble fighting C# syntax... I don't need to add something else I completely don't get. :unsure: Thanks ahead of time! Gordon

#2 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 28 April 2011 - 07:04 AM

I make beer.
My project goal is connect 6 thermistors to the Net+ and map the temperature profile in my mash tun throughout a mash. An app running on my PC would connect to the Net+ vis ethernet and collect that temperature data to trend/log/whatever. The main point being a learning Net+ project that provides some useful results.

That ethernet connection (sockets I guess) is where I need some patient help. I ran the webserverhello world example and that was pretty cool, but that really doesn't fit my project.

Maybe there is already an example of how to do this here, but everything I've found so far seems to be interested in http only. Maybe that will be a next step for me, but right now I'm having enough trouble fighting C# syntax... I don't need to add something else I completely don't get. :unsure:



Firstly, welcome to the community.

From what I have read of your requirements there is no reason why you cannot use the web server project found here. I have written a couple of projects connecting a PC to a web server - I did it using Silverlight rather than a WinForms application but I have also seen some post which suggest that there has been some connectivity to the N+ using WinForms. You would simply need to have the WinForms application poll the web server periodically and have the web server gather the readings and send them back in response.

Another possibility (as you have some com port programming experience would be to use RS232 - you would need some additional hardware to convert the sgnals from the N+ to RS232 levels but there is hardware out there to do that for you. You could even do this with a Bluetooth module and have a wireless system. These modules just act like com ports - if the data is not commercially sensitive then they just plug and go.

Hope this helps,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 April 2011 - 08:35 AM

Mark has pointed right the question.

Just a little note, because it depends on your target app.
You may have two different scenario:
  • your N+ is a web-server as Mark described, so that you will have a client somewhere that should connect to your board;
  • your N+ is also a client, but it acts a data provider (i.e feeder) for a PC server, then a UI client should connect to that server, instead of the board.

The first is much simpler and finalized to *that* board: it is a game for two, a client and a N+.

The second is more complex, but much more powerful also. You may have several data providers (e.g. Netduinos, PCs, 3rd part devices, etc), each one provide its own data to the server. The result is somewhat aggregating data, where you may compose your own application (desktop or web) limited only by imagination.

Cheers and welcome from me too.
Biggest fault of Netduino? It runs by electricity.

#4 PawleysPlayr

PawleysPlayr

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 April 2011 - 04:31 PM

Mark and Mario thanks for the Welcome(s). :) Mario your second method is more along what I was envisioning...think distributed I/O in the industrial world. I was thinking initially that the webserver route would be more difficult for me because of my lack of experience with web apps in general. Sounds like this isn't the case and I'll make the solution Mark described my first project. I am still interested in the second approach though. If you guys come across any example code discussions that make that client to server ethernet connection I'd appreciate your pointing them out to me. Thanks! Gordon

#5 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 28 April 2011 - 06:17 PM

I was thinking initially that the webserver route would be more difficult for me because of my lack of experience with web apps in general.

-snip

If you guys come across any example code discussions that make that client to server ethernet connection I'd appreciate your pointing them out to me.


The web app route is not too difficult if you keep in mind what you are trying to do. I created a project a while ago to perform data logging with the results being presented in Silverlight. The data was generated by an NE555 timer but there is nothing to stop you collecting data from several analog data sources and logging that. You can find the post in the project showcase forum here and some further discussions on my blog here. Whilst this project uses Silverlight there should be no barriers to creating a WinForms application to collect the data from multiple devices on a network.

From the server point of view I think that the principles are there in the web server projects you can find in the project showcase.

On the desktop side you do not need to think of this as a web porject. It can be a standard WinForms application which consumes the data from a web server.

Hope this helps,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#6 PawleysPlayr

PawleysPlayr

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 April 2011 - 11:43 AM

Mud on my face I guess. I was looking everywhere for examples but under my nose. <_< Stumbled across the samples that came with the Microsoft Micro Framework. The Socket Client and Server Projects were there. I was able poll the Net+ running that project for AIN values. Nice! :D I'll look thru your 555 Timer project to learn how you approached the communications. Thanks for the link! Next to figure out how to hard code the Net+ IP address. My thermistors should arrive next week. I plan to use the thermistor calcs on the Net+ then send both that calculated temperature and the raw analog to the winform app. The purpose being to recheck the calc there and compare differences.

#7 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 29 April 2011 - 01:46 PM

Next to figure out how to hard code the Net+ IP address.


You can set the IP address on the N+ using MFDeploy.

Look for the Network item under the Target -> Configuration menu item.

Regards,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#8 PawleysPlayr

PawleysPlayr

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 April 2011 - 11:10 PM

Nice. I had never even seen a forum post that mentioned the MFDeploy. Worked great. Thanks Mark! Gordon

#9 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 30 April 2011 - 04:13 PM

I had never even seen a forum post that mentioned the MFDeploy.


It's a tool you'll need every now and then. Other situations you might need it for are unlocking a mis-behaving N+ application (you can use the tool to force the erasure of an application you've written) and upgrading firmware. I'm sure there is more but they are the main uses I've found for it.

Regards,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#10 PawleysPlayr

PawleysPlayr

    Member

  • Members
  • PipPip
  • 11 posts

Posted 24 May 2011 - 02:00 PM

Ok...I'v made some headway, but now I need a little help. There's something screwy about the way I'm using the socket send method. The problem is: When the program runs item.Send(bytesSend); in the SendNewData method I get the errors I've copied from my immediate window below. What I'm trying to do is create a list of socket clients that are registered to receive messages. When a client registers, I open the socket connection and add that socket to the arraylist of sockets. At timed intervals the SendNewData method is called. My idea was for it to loop thru the list of sockets and send the data to each one. Any ideas? private static ArrayList _registeredClients = new ArrayList(); private void _addClientSocket(string ip) { //create the socket...test the connection...add the socket to _registeredClients arraylist try { // Create a socket connection with the specified server and port. Socket tempSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); tempSocket.Bind(new IPEndPoint(IPAddress.Any, _sendPort)); tempSocket.Connect(new IPEndPoint(IPAddress.Parse(ip), _sendPort));// try to connect if (tempSocket != null)// is the socket connected? { // add the new socket to the clients arraylist. _registeredClients.Add(tempSocket); } } catch (SocketException e) { Debug.Print(e.Message.ToString()); } } public void SendNewData(string AINData) { if (_registeredClients.Count > 0)//Make sure there are clients to send to { Byte[] bytesSend = Encoding.UTF8.GetBytes(AINData);//convert the string to byte array as required by socket.send method foreach (Socket item in _registeredClients) { if (item != null) { Debug.Print(item.RemoteEndPoint.ToString()); item.Send(bytesSend); } } } } Immediate Window: 10.10.10.106:56890 #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (4) #### #### Message: #### Microsoft.SPOT.Net.SocketNative::connect [IP: 0000] #### #### System.Net.Sockets.Socket::Connect [IP: 001d] #### #### ClientCommHandler.CClientHandler::SendNewData [IP: 005f] #### #### ClientCommHandler.CTrafficCop::SendNewData [IP: 000d] #### #### DLogger.Program::_thermistorHandler_NewTemperaturesHandler [IP: 000b] #### #### ThermistorInterface.CThermisterHandler::SendTemperatures [IP: 001c] #### #### ThermistorInterface.CThermisterHandler::UpdateTemperatures [IP: 0028] #### #### SocketException ErrorCode = -1 #### SocketException ErrorCode = -1 A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll #### SocketException ErrorCode = -1

#11 ColinR

ColinR

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationCape Town, South Africa

Posted 24 May 2011 - 07:03 PM

I get the same errors on connect periodically, from what I can gather it's RAM related. What is your free RAM around this point?

#12 PawleysPlayr

PawleysPlayr

    Member

  • Members
  • PipPip
  • 11 posts

Posted 26 May 2011 - 09:23 PM

The RAM was fine...+40K. Turns out there is something screwy going on with the sockets collection. In the SendNewData Method the RemoteEndpoint is getting changed at the item.Send ie this code: Debug.Print(item.RemoteEndPoint.ToString()); item.Send(bytesSend); Debug.Print(item.RemoteEndPoint.ToString()); Result: "10.10.10.106:56890" at the first debug statement then "8.5.0.0:0" or something similar at the second debug statement So the next time the SendNewData was called, that invalid RemoteEndpoint would throw an exception. I have no idea what is happening there. In the short term ... just so I can move forward ... I've changed the code to save an arraylist of string IP addresses. It works fine, but now I have to create a new socket for each client and connect before I can send the next message. Just seems like it would be better to keep the socket intact once it's connected. I don't know anything about how sockets and their connections really work. I was just assuming the connections were persistant. Is that not the case?




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.