Webserver

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #4732
    Author Image
    Tcm0
    Participant

    I just found out that MonoBrick has an integrated webserver in MonoBrickFirmware.Services.WebServer but I can’t find out how to run it. Or is it possible that it doesn’t work using the RNDIS USB connection? Do I have to make sure that I access a special port?

    #4734
    Author Image
    Anders Søborg
    Keymaster

    Hi

    It is correct that you can run a web-server on the EV3 and host a ASP.NET site. However it did not quite perform the way we want so for now it has been disabled from the firmware application. Have a look at the firmware application line 42. It is still part of the firmware dll but will fail to start since the webserver is not part of the current image. As soon as we have it working we will upload a new image.

    /Anders

    #5040
    Author Image
    Pang Chee Chong
    Participant

    I have tried leJOS and it is hosted in the ev3 brick which can be controlled by any device that is connected in the same network (is thr any solution for different network?). Is there any way like hosting an ASP.net online website somewhere outside rather then on the EV3, so i can still able to control ev3 during my oversea trip.

    #5041
    Author Image
    Tcm0
    Participant

    “I have tried leJOS and it is hosted in the ev3 brick which can be controlled by any device that is connected in the same network (is thr any solution for different network?).”
    You can open the port to access the website (probably 8080 redirect to 80). Then everything can access to the server from the internet. But you have to get the online IP somehow.

    “Is there any way like hosting an ASP.net online website somewhere outside rather then on the EV3, so i can still able to control ev3 during my oversea trip.”
    You can run a webserver on a computer which can access the EV3 through the MonoBrick communication library.

    #5042
    Author Image
    Anders Søborg
    Keymaster

    Hi there.

    The webserver example found in the master branch is working. Simply compile the project and upload the program to your EV3. When the webserver has started (which takes a while) simply type in http://yourIp:yourPort/documentation to see a list of what is currently supported. Please note that using port 80 is not working so use something like 8080. As you will see from the URL list the webserver is written as a REST service so data is retrieved via JSON – so writing a client that that can interact/control the EV3 is fairly simple.

    /Anders

    Attachments:
    You must be logged in to view attached files.
    #5151
    Author Image
    Jacek S
    Participant

    Hi Anders,

    I have used the Nancy framework for my javascript touchscreen joystick controller project. The Nancy self hosted server is used to host all static content like html and js files and the rest service where the joystick position is posted from javascript (all is hosted on the ev3 brick). Unfortunately the Nancy server performance is very poor. Often the delay between ajax post and the handler reaction takes 1-2sec. It can’t be used for realtime steering. I was thinking about using HttpListener class. Do you have any experience with this class on the brick?

    Jacek

    #5152
    Author Image
    Anders Søborg
    Keymaster

    Hi Jacek

    Often the delay between ajax post and the handler reaction takes 1-2sec

    Are you sure about that – my experience is that the first time you make a request/post it takes some time (since everything must be JIT compiled) but from then on it runs very smooth… we are looking into AOT compiling the Nancy DLL’s but until this is working you will just have to live with the fact that the first time something is executed it takes a while.

    /Anders

    #5155
    Author Image
    Jacek S
    Participant

    Hi

    The starting time is the next thing that I don’t like.
    Yes I’m sure, I did many tests yesterday. My test program is configured to send ajax posts with 250ms breaks (when the position of joystick is changed). This means that Nancy on the brick have problem with handling 4 requests per second.

    handler code:

    
                Post["/joypos"] = x => 
                {
                    JoyPos pos = this.Bind();
                    LcdConsole.WriteLine("X:{0} Y:{1}",pos.X,pos.Y);
                    var speed = (sbyte) (pos.Y > 100 ? 100 : pos.Y < -100 ? 100 : pos.Y);
                    if (speed == 0) 
                        motor.Off();
                    else 
                        motor.SetSpeed(speed);
                    return Response.AsJson(pos);
                };
    

    poster code:

    
    var timer = $.timer(function () {
        if (Math.abs(x - lastx) > 5 || Math.abs(y - lasty) > 5) {
            lastx = x;
            lasty = y;
            $.post("/truck/joypos", { X: x, Y: y});
        }
    });
    timer.set({ time: 250, autostart: true });
    
    • This reply was modified 9 years, 10 months ago by Author ImageJacek S.
    #5158
    Author Image
    Anders Søborg
    Keymaster

    Hi Jacek

    The starting time is the next thing that I don’t like.

    Yes this is a killer – and also one of the reasons why this has not been officially released yet!

    Since I don’t have all your code it is hard to tell where the bottleneck is located – have you tried to time the execution? Just for information whenever Nancy handles a new request the “Module” that handles the request is created/constructed – if you are not aware of this it might give you some unexpected behaviour.

    /Anders

    #5159
    Author Image
    Anders Søborg
    Keymaster

    Hi again

    Why do you have a return value in the post handler code? Return values should only be used for GET

    /Anders

    #5160
    Author Image
    Jacek S
    Participant

    Hi,

    Yes, I forgot to remove this. I will do more tests today.

    Jacek

    #5162
    Author Image
    Jacek S
    Participant

    Hi Again,

    Now my handler body is empty:

    
                Post["/joypos"] = x => 
                {
                    return "";
                };
    

    Look at the attached network log.

    Jacek

    Attachments:
    You must be logged in to view attached files.
    #5164
    Author Image
    Jacek S
    Participant

    Hi Again,

    I have created own simple HTTP server. Now I have great performance 🙂

    
        class Program
        {
            static void Main(string[] args)
            {
                HttpListener httpListener = new HttpListener();
                httpListener.Prefixes.Add("http://*:9090/");
                httpListener.Start();
                var run = true;
                (new ButtonEvents()).EscapePressed += () => run = false;
                while (run)
                {
                   var context = httpListener.GetContext();
                   Process(context);
                }
            }
    
            public static string RootPath
            {
                get
                {
                    string filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
                    return Path.GetDirectoryName(filePath) + "/" ;
                }
            }
    
            static string GetContentType(string ext)
            {
                switch (ext.ToLower())
                {
                    case ".js":
                        return "text/javascript";
                    case ".htm":
                    case ".html":
                        return "text/html";
                    case ".png":
                        return "image/png";
                    case ".jpg":
                        return "image/jpg";
                    case ".css":
                        return "text/css";
    
                    default:
                        return "application/octet-stream";
                }
            }
    
            private static void Process(HttpListenerContext context)
            {
                string reqPath = context.Request.Url.AbsolutePath;
                //Console.WriteLine(reqPath);
                if (reqPath == "/truck/joypos")
                {
                    context.Response.StatusCode = 200;
                    context.Response.Close();
                    return;
                }
                reqPath = Path.Combine(RootPath, reqPath.Substring(1));
                if (!File.Exists(reqPath))
                {
                    context.Response.StatusCode = 404;
                    context.Response.Close();
                    return;
                }
                var contentType = GetContentType(Path.GetExtension(reqPath));
                context.Response.Headers[HttpResponseHeader.ContentType] = contentType;
                var content = File.ReadAllBytes(reqPath);
                context.Response.OutputStream.Write(content, 0, content.Length);
                context.Response.Close();
            }
        }
    

    Jacek

    #5165
    Author Image
    Anders Søborg
    Keymaster

    Sweeeeet – what about the startup time -:)

    /Anders

    #5166
    Author Image
    Anders Søborg
    Keymaster

    Hi again

    Concerning the time latency in your example. What does it show? That sometimes it takes 134ms but most of the time it takes more that two seconds?

    Also could you please post the code for the both the model and module

    /Anders

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic.

Posted in

Make a donation