Home→Forums→MonoBrick Communication Library→Communication via wifi on ev3
Tagged: wifi ev3
- This topic has 4 replies, 3 voices, and was last updated 9 years, 5 months ago by Samuel Otero.
-
AuthorPosts
-
June 18, 2015 at 07:43 #5429
Martin KnudsenParticipanthi, I have the monobrick firmware installed on the EV3 with EDIMAX wifi.
I can run programs on the ev3 using wifi with the monobrickfirmware library from xamarin studio, so
I know wifi works and I can transfer programs to the brick and run them (such as this snippet – from the webpage):
using MonoBrickFirmware;
//other code here
InfoDialog dialog = new InfoDialog (“Attach a motor to port A and B”, true);
dialog.Show ();//Wait for enter to be pressed
//var ev3 = new Brick<Sensor,Sensor,Sensor,Sensor>(“wifi”);
Motor motorA = new Motor (MotorPort.OutA);
motorA.SetSpeed (50);
That works fine.
But using the communication library, I get errors running the following program (just the relevant code below)static void Main(string[] args)
{
var ev3 = new Brick<Sensor,Sensor,Sensor,Sensor>(“wifi”);
try{
ev3.Connection.Open(); //failed to open connection error here – see below
ev3.MotorA.On(50);
System.Threading.Thread.Sleep(3000);
ev3.MotorA.Off();
}
catch(Exception e){ //I have failure code here
}
finally{
ev3.Connection.Close();
}It compiles and transfers to the brick and runs on the brick I can see.
But the line “ev3.Connection.Open();” fails – see below for console output:mono –debug –debugger-agent=transport=dt_socket,address=0.0.0.0:12
345,server=y ‘./apps/WifiCommander/WifiCommander.exe’
at MonoBrick.WiFiConnection`2[MonoBrick.EV3.Command,MonoBrick.EV3.Reply].Open () [0x00000] in <filename unknown>:0
at Program.Main (System.String[] args) [0x00013] in C:\Users\makn\Documents\Projects\WifiCommander\WifiCommander\Main.cs:10
Error: Failed to open connection
Press any key to end…Any ideas to why this fails are welcome!
(I assume the monobrick communication library will work on the monobrick firmware – so should not be the problem?).June 18, 2015 at 14:11 #5430
Anders SøborgKeymasterHi Martin
I assume the monobrick communication library will work on the monobrick firmware – so should not be the problem?
No that is not the case. The MonoBrick firmware has no implementation for the LEGO direct or system protocol.
With the MonoBrick EV3 firmware you have a lot of other possibilities for remote controlling your EV3. The most obvious is to use a socket connection. You can use this example to get started.
Another option is to look at the webserver example found here. This will let you control the brick from a browser. This guy wrote his own
webser that lets him control the robot from any phone or PC/Mac via a browser. Hope this answers your question./Anders
June 22, 2015 at 11:34 #5433
Martin KnudsenParticipantok, great.
So I got the code from https://github.com/Larsjep/monoev3/tree/master/MonoBrickWebserverEV3Test
running on the EV3 (with the monobrick firmware).It works (from xamarin studio it refuses to deploy this project on the project, citing some strange build error (but it does build a .exe)), and I copied this .exe and .dll to the brick with winSCP and it works) and I can connect to the webserver running on the ev3 (I made a simple index.html) from a webbrowser running on my pc (of course via port 8080) with the EDIMAX wifi.
That’s great!
But just to know if I am on the right track with my project:
I want to now build a simple webpage with controls now (using just html and javascript), which will then enable
users via the pc browser to issue simple commands to the ev3 brick.Is this possible?
I am wondering to call methods from the MonoBrickFirmware library from javascript code?Or should should I just be using HTTP post/get in a form in the .html and then have a callback method on the brick in the c# program to handle the post/get and then I can call the MonoBrickFirmware from that callback method? (and how to setup this callback method on the EV3?)
June 24, 2015 at 07:42 #5434
Anders SøborgKeymasterHi there
Sorry for the late reply. If you want to run commands from a website simply make Nancy return a webpage like
this this (I know that there is a lot of bad javascript code in this file so no need to mention that 🙂You also need to define the URL that does something. Look at
this example.
If you finde the code in the webserver example confusing then make your own Nancy example shown in this totorial
here.
If you find the speed of Nancy a problem then use this
code as a starting point (This is code for the controller for the LEGO truck I posted in a previous post).
Please write if you have questions
/Anders
June 25, 2015 at 22:41 #5442
Samuel OteroParticipantI just needed to say that this post is so f** good. Good information here. Thank you for sharing guys.
-
AuthorPosts
You must be logged in to reply to this topic.
Follow