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

How to use the new functionalities


  • Please log in to reply
37 replies to this topic

#21 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 24 September 2010 - 10:20 PM

SD card:
System.IO.dll

Network:
Microsoft.SPOT.Net.dll

To change your static IP (or to test out the "unsupported" DHCP):
Run MFDeploy. Target menu > Configuration > Network

We haven't even made the announcement yet, and community members are already building stuff :) Fantastic!

Chris



I dont have a Microsoft.SPOT.Net. Do I need an update for .NET MF ?

EDIT

Make sure you click on the references text inside the Solution explorer and then go to add reference, then all the .NET MF stuff will show up and go down to Microsoft.SPOT.Net

#22 Chris Seto

Chris Seto

    Advanced Member

  • Members
  • PipPipPip
  • 405 posts

Posted 24 September 2010 - 10:26 PM

FTR: I have never encountered a single NIC that didn't know to automatically go into crossover mode.

#23 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 September 2010 - 04:02 AM

Correction: it's the System(.dll) assembly that you need to add for networking. You only need to add Microsoft.SPOT.Net(.dll) if you want to change your IP settings in code... Chris

#24 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 25 September 2010 - 04:31 AM

Correction: it's the System(.dll) assembly that you need to add for networking.

You only need to add Microsoft.SPOT.Net(.dll) if you want to change your IP settings in code...

Chris


Socket output = new Socket(AddressFamily.Unknown, SocketType.Unknown, ProtocolType.IPv6);

What should be used instead of what I have there? I get a socket exception, nothing specific, it just says socket exception right on that line.

EDIT:


now I get tan error here:
output.Send(Encoding.UTF8.GetBytes("Hello World!"), 12, SocketFlags.None);

do I call .Connect first? I would imagine I have to, but what is theis EndPoint thing and how do I use it (new EndPoint doesnt work and there is no EndPoint.Something)?

#25 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 September 2010 - 04:35 AM

oz, AddressFamily should be InterNetwork, SocketType should be Stream, ProtocolType should be Tcp. Chris

#26 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 25 September 2010 - 04:39 AM

oz,

AddressFamily should be Tcp, SocketType should be Stream, ProtocolType should be IPv4.

Chris

you posted while I edited it.... I found out after check the first page, thats what happens after 10:00 pm :)

anyways the edit shows a new error/question, can you help with that?

edit: wait... there is no TCP in the address family

#27 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 September 2010 - 04:51 AM

you posted while I edited it.... I found out after check the first page, thats what happens after 10:00 pm :)

anyways the edit shows a new error/question, can you help with that?

edit: wait... there is no TCP in the address family


Sorry, I need to sleep before I answer questions like that... Here are the correct values. :)

AddressFamily.InterNetwork
SocketType.Stream
ProtocolType.Tcp

I have edited them in my post above so I don't confuse anyone :)

Chris

#28 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 25 September 2010 - 05:03 AM

Sorry, I need to sleep before I answer questions like that... Here are the correct values. :)

AddressFamily.InterNetwork
SocketType.Stream
ProtocolType.Tcp

I have edited them in my post above so I don't confuse anyone :)

Chris


SAme here, I guess I am the first to lock up the Netduino Plus <_< ... MF deploy didnt fix it, 3V3 to /RESET didnt fix it... this is the code.

        public static void Main() 
        {
            using (Socket output = ConnectSocket("192.168.1.46", 50))
            {
                    output.Send(Encoding.UTF8.GetBytes("Hello World!"));
            }
        }

        /// <summary>
        /// Open Socket to given Server and Port
        /// From: SocketClient example
        /// </summary>
        /// <param name="server">Server</param>
        /// <param name="port">Port</param>
        /// <returns>New Socket</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;
        }

the bottom method is from your weather thing.

I guess I have to do the completely erease with the gold square [which is now a little ball of solder?] and all that mess right?

#29 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 September 2010 - 11:31 AM

I guess I have to do the completely erease with the gold square [which is now a little ball of solder?] and all that mess right?


Oz,

It's pretty hard to break a Netduino using software, so let's see if we can fix this by simply erasing the offending Netduino app... [It sounds like you tried this, but let's try it again.]

1. Unplug your Netduino Plus from your PC
2. Start up MFDeploy, select USB transport
3. Hold down the pushbutton on your Netduino Plus while plugging it into your PC
4. Immediately press PING in MFDeploy...you should see "TinyBooter...Netduino Plus by Secret Labs"
5. Now, press ERASE and confirm YES.
6. Unplug and re-attach your Netduino Plus. It should be all better.

If you've set some invalid IP address settings, you may need to use Target > Configuration > Network in MFDeploy immediately upon plugging in your Netduino Plus...and then set the values to safe values.

Of course if all else fails, the "erase and reflash" process works well too. But that's the backup, backup plan.

Also...if you can create a solution which causes .NET MF to lock up, we can debug it on our end.

Chris

#30 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 September 2010 - 11:32 AM

Maybe the FileStream buffers dont get released properly ?

Can anyone else try to run this code and see if it works fine on their Netduino Plus?


Ooh, great find. Could you please post your solution in a ZIP file so we can download it here and try it out?

[BTW, please note that MakerFaire NY is today and it's the weekend...so it may take a day or two to look at this in depth...]

Chris

#31 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 25 September 2010 - 03:29 PM

If you've set some invalid IP address settings, you may need to use Target > Configuration > Network in MFDeploy immediately upon plugging in your Netduino Plus...and then set the values to safe values.


That fixed it! Umm yeah I don't really know what unsafe IPs are... I had it on 192.168.1.50, the computers on my network are 192.168.1.45/46/47. What is a safe address? The default gateway should be my router's address(192.168.1.1) right?

EDIT:
It locked up again after deploying this:
            using (System.Net.Sockets.Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {

                IPHostEntry entry = Dns.GetHostEntry("192.168.1.46"); // this is my computer's ip
                IPAddress address = entry.AddressList[0];
                IPEndPoint endpoint = new IPEndPoint(address, 20);

                socket.Connect(endpoint);
                socket.Send(Encoding.UTF8.GetBytes("Hello World!"));
            }


#32 pascal06

pascal06

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts
  • LocationFrance

Posted 25 September 2010 - 06:34 PM

Yes, the default gateway address means your router's address ... When your Netduino need to communicate with a destination address not in your subnet, it will send this packet to this address by default. If no other static route in Netduino match this destination. But in your case, you probably not need to specify any other static route. Pascal

#33 hari

hari

    Advanced Member

  • Members
  • PipPipPip
  • 131 posts

Posted 25 September 2010 - 08:53 PM

There's also the System.Http assembly...which gives you the ability to download and parse web pages with ease. It _might_ be too big if you're running a sophisticated program--but it might not be. Feel free to play with it, and maybe we can free up some additional flash for code as well...

I was able to download Netduino's home page with this code, but you're so right Chris. It's pretty big. Increasing buffer to 1024 threw an out of memory exception. So, reader.ReadToEnd() is out of the question. I guess we need something smaller or free up more memory.

Will my app automatically use SDcard as extra memory? or is it only for data storage?

WebRequest request = HttpWebRequest.Create("http://www.netduino.com");
WebResponse response = request.GetResponse();

Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);

const int bufferMax = 512;  //1024 ran out of memory.
int charsRead = -1;
while (charsRead != 0)
{
    char[] buffer = new char[bufferMax];
    charsRead = reader.Read(buffer, 0, bufferMax-2);
    if (charsRead > 0)
    {
        buffer[charsRead+1] = (char)0;
        Debug.Print(new string(buffer));
    }
}


#34 Ward

Ward

    Member

  • Members
  • PipPip
  • 22 posts

Posted 25 September 2010 - 10:18 PM

That fixed it! Umm yeah I don't really know what unsafe IPs are... I had it on 192.168.1.50, the computers on my network are 192.168.1.45/46/47. What is a safe address? The default gateway should be my router's address(192.168.1.1) right?

EDIT:
It locked up again after deploying this:


I've been having some similar issues here, and I think I narrowed it down to port behavior at the destination (my PC). With Windows Firewall enabled, port 80 worked fine, but port 8080 caused the nasty hang that you've been experiencing. I tried opening port 8080 in Windows Firewall, to no avail. Finally I got pissed and disabled Firewall completely, now when connecting to port 8080 I get an exception, SocketException 10054. That exception appears to relate to premature port closure by the remote host, so I'll consider that an improvement. At least I don't have to do the MFDeploy-button-press dance any more.

#35 Ward

Ward

    Member

  • Members
  • PipPip
  • 22 posts

Posted 25 September 2010 - 10:33 PM

Dang it, posted too soon! The SocketException was a result of the Python script I was running on my PC not actually listening on the port. All fixed, works fine. Netduino code is as follows:

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using Microsoft.SPOT.Net.NetworkInformation;
using Microsoft.SPOT.Net;
using System.Net.Sockets;
using System.Net;
using System.Text;

namespace NetduinoApplication1
{
    public class Program
    {
        public static void Main()
        {
            using (System.Net.Sockets.Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                IPHostEntry entry = Dns.GetHostEntry("192.168.1.102");
                IPAddress address = entry.AddressList[0];
                IPEndPoint endpoint = new IPEndPoint(address, 8080);

                socket.Connect(endpoint);
                socket.Send(Encoding.UTF8.GetBytes("Hello Netduino Plus"));
            }
        }
    }
}

And the Python code is:

from socket import * 
HOST = '192.168.1.102'
PORT = 8080
BUFSIZ = 1024
ADDR = (HOST, PORT)
serversock = socket(AF_INET, SOCK_STREAM)
serversock.bind(ADDR)
serversock.listen(2)

print 'Waiting for connection...'
clientsock, addr = serversock.accept()
print 'connected from:', addr
while 1:
	data = clientsock.recv(BUFSIZ)
	if not data: break 
	print data
clientsock.close()
serversock.close()


#36 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 25 September 2010 - 10:54 PM

To make it complete.. here is how to receive data

//code

Have fun !!!


I got that to work! Now how do I listen for data constantly? Because so far I have only been able to send one command.

#37 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 02 October 2010 - 08:53 PM

I was just about a post a "why doesn't it work" question, but solved it myself... If no networking functionality is working and no LEDs light up when you plug the ethernet cable in, you've probably flashed your Netduino Plus with the 4.1.0.4 firmware meant for your standard Netduino. :huh:

#38 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 October 2010 - 09:05 PM

If no networking functionality is working and no LEDs light up when you plug the ethernet cable in, you've probably flashed your Netduino Plus with the 4.1.0.4 firmware meant for your standard Netduino. :huh:


:)

Just FYI, we fully support the use of the standard Netduino firmware on the Netduino Plus. You'll lose the integrated networking (and the MicroSD card feature--but only for a few weeks)--but we designed the two boards to be electrically compatible.

We figured that some Netduino Plus users wouldn't need the networking and would want to erase-and-reflash to double the amount of Flash/RAM available to their programs. There's no harm in switching back and forth between the two on the Netduino Plus.

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.