Communication via wifi on ev3

HomeForumsMonoBrick Communication LibraryCommunication via wifi on ev3

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by Author Image Samuel Otero 1 year, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5429
    Author Image
    Martin Knudsen
    Participant

    hi, 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?).

    #5430
    Author Image
    Anders Søborg
    Key Master

    Hi 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

    #5433
    Author Image
    Martin Knudsen
    Participant

    ok, 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?)

    #5434
    Author Image
    Anders Søborg
    Key Master

    Hi 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

    #5442
    Author Image
    Samuel Otero
    Participant

    I just needed to say that this post is so f** good. Good information here. Thank you for sharing guys.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Posted in

Make a donation