How To Establish A WiFi Connection With The EV3

This guide descries how to establish a WiFi connection with the EV3 LEGO Mindstorms brick using the standard firmware. Before you can establish a connection you need a USB WiFi dongle that is supported by the firmware. Currently only one dongle is supported namely the NetGear WNA1100. Once you got your hands on one follow the description below to make the brick connect to a network.

Connecting the EV3 to a network

If everything works out right you should now be connected to a WiFi network. Now it is time to establish a connection as shown in the next step.

Establishing a TCP/IP connection with the EV3

Since connecting to the brick is not as strait forward as just opening a TCP/IP connection I have provided a Wireshark dump of a connection sequence. Overall the following steps are needed to unlock the EV3 brick and make it accept a TCP/IP connection.

  • Listen for a UDP broadcast from the EV3 on port 3015
  • Send a UDP message back to the EV3 to make it accept a TCP/IP connection
  • Establish a TCP/IP connection on port 5555
  • Send a unlock message to the EV3 over TCP/IP

Listening for UDP broadcast

Approximately every 10 seconds the EV3 will broadcast a UDP message on port 3015. The message is 67 bytes in size and contains the following text:

Serial-Number: 0016533f0c1e
Port: 5555
Name: EV3
Protocol: EV3

The serial number is needed when establishing a TCP/IP connection later on so remember it. Also the source port used for the UDP broadcast must also be the port used in the next step where we send a UDP message back to the brick to let it know that we wish to establish a TCP/IP connection.

Sending a UDP message back to the EV3

The contents of the data is irrelevant so just send a single byte. The important thing is that you send it to the source port that was used in the bricks broadcast message ( this is not port 3015). Once a message has been send the brick is ready to accept a TCP/IP connection.

Establish a TCP/IP connection

Connect to the brick using TCP/IP on port 5555 and use this connection to send the unlock message

Sending the unlock message

The unlock message has the following format:

GET /target?sn=0016533F0C1E VMTP1.0
Protocol: EV3

Where 0016533F0C1E is the serial number from the UDP broadcast. The brick should now reply with a 16 byte TCP/IP message with the following text:

Accept:EV340

indicating that the connection has been established. Now you should be able to send both system and direct commands to the brick over a WiFi connection.

Sending data over WiFi using the MonoBrick communication library

Below some sample code for the MonoBrick communication library is shown. Here a WiFi connection is used to control motor A.

using System;
using MonoBrick.EV3;
namespace Application
{
	public static class Program{
	  static void Main(string[] args)
      {

		try{
			var ev3 = new Brick<Sensor,Sensor,Sensor,Sensor>("WiFi");
			sbyte speed = 0;
			ev3.Connection.Open();
			ConsoleKeyInfo cki;
			Console.WriteLine("Press Q to quit");
			do 
			{
				cki = Console.ReadKey(true); //press a key
				switch(cki.Key){
					case ConsoleKey.R:
						Console.WriteLine("Motor A reverse direction");
						ev3.MotorA.Reverse = !ev3.MotorA.Reverse;
					break;							
					case ConsoleKey.UpArrow: 
						if(speed < 100)
							speed = (sbyte)(speed + 10);
						Console.WriteLine("Motor A speed set to " + speed);
						ev3.MotorA.On(speed);
					break;
					case ConsoleKey.DownArrow: 
						if(speed > -100)
							speed = (sbyte)(speed - 10);
						Console.WriteLine("Motor A speed set to " + speed);
						ev3.MotorA.On(speed);
					break;
					case ConsoleKey.S: 
						Console.WriteLine("Motor A off");
						speed = 0;
						ev3.MotorA.Off();
					break;
					case ConsoleKey.B:
						Console.WriteLine("Motor A break");
						speed = 0;
						ev3.MotorA.Brake();
					break;
				}
			} while (cki.Key != ConsoleKey.Q);
		}
		catch(Exception e){
			Console.WriteLine("Error: " + e.Message);
			Console.WriteLine("Press any key to end...");
			Console.ReadKey();				
	  	}
	  }
	}
}
32 comments on “How To Establish A WiFi Connection With The EV3
  1. Author Image jason says:

    Anders, I’m fantastically impressed by what you’ve done. I just got an EV3 for me and my son and we’re hoping to build a remote (i.e. over the web) control for our creations for our friends to try. Am I right in thinking MonoBrick will enable us to communicate with the EV3 Brick over wifi (assuming we get the dongle) and pass commands directly to the brick? If so, that’s truly great and can’t wait for the release.

    Thanks,

    Jason

  2. Hi! I just got my hands on an Ev3 myself and I am searching for a library to control it using Linux. Your project sounds great and so I just wanted to ask if you already know when your amazing work will be available for us?

  3. Author Image mind says:

    Dear all,
    how to put in in the wpa2 key the dash ‘-‘. Ev3 don’t accept these.
    br. Mind

  4. Author Image Miguel Valenzuela says:

    Do you know if there is a way to run a program on the EV3 from the iPad?

  5. Author Image Yan says:

    Does this workflow works with wired network connection (use usb ethernet adaptor to connect EV3 into the network)?

  6. WiFi connection – how to/ using OSX Mavericks

    1. plug in (Netgear) WiFi dongle to EV3 brick
    2. connect EV3 to MacBook via USB cable. THIS IS IMPORTANT.
    3. In EV3 software go to Tools – Wireless Setup
    4. Select your WiFi Base station when it appears in the list
    5. Select Connect
    (note that on the EV3 you can see that the WiFi option has now been selected too automatically)
    6. Unplug USB cable and the WiFi connection will become your primary connection to EV3 and MacBook; you can see the WiFi symbol in bottom right pane of EV3 software.

    This is not so intuitive as you must also repeat this procedure (remembering to plug in the USB cable again) if you restart your EV3 brick. To be fair to LEGO, the EV3 software has a pop up alert telling you to connect a USB cable if you try to re-establish a WiFi connection once again after starting up EV3 brick.

  7. Author Image NP says:

    Hi

    While trying to establish a TCP/IP connection with EV3.I could see the UDP broadcast with the serial number and the corresponding port number. But I am unable to send the UDP messages back to EV3 to make it accept the TCP/IP connection. Kindly provide steps as to how do I send a UDP message back to the EV3.

  8. Author Image Ludwig says:

    In the part above where you say to send a UDP reply you say to send the reply to the port number in the original UDP message that was received and then you say to establish a TCP/IP connection (I assume here you mean a TCP connection since UDP is also a part of the TCP/IP protocol suite) on the same port, but you can’t send a UDP datagram to a TCP port so I am a bit confused. Will the EV3 be listening on the same port number for UDP datagrams as for TCP connections?

  9. Author Image minghan Li says:

    HI
    I only have EDIMAX EW-7811-Un.
    It also can Connecte the EV3 to a network?

  10. Author Image Dean says:

    I actully don’t use the USB
    Is it possible to use standard WiFi

  11. Author Image FD says:

    There is no built in WIFI in the EV3, but pretty much space inside the housing. Even without unsoldering the usbport from the NETgearStick, the stick will fit inside.
    I did that a few times.
    And i can send pictures to anyone who is courageous enough to open the brick an do some soldering.

  12. Author Image Human says:

    Is there any solution to connecting to a network which has a proxy configuration to it through the EV3?

  13. Author Image Annabelle says:

    My father just got me an Ev3 and I was wondering if you knew any wireless adapters you could use for it except for the Netgear N150?

Download

Make a donation