Home→Forums→MonoBrick EV3 Firmware→Webserver
- This topic has 16 replies, 4 voices, and was last updated 9 years, 10 months ago by Tcm0.
-
AuthorPosts
-
August 30, 2014 at 22:14 #4732
Tcm0ParticipantI 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?
August 30, 2014 at 22:23 #4734
Anders SøborgKeymasterHi
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
December 7, 2014 at 17:56 #5040
Pang Chee ChongParticipantI 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.
December 7, 2014 at 19:35 #5041
Tcm0Participant“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.December 7, 2014 at 22:38 #5042
Anders SøborgKeymasterHi 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.December 30, 2014 at 09:16 #5151
Jacek SParticipantHi 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
December 30, 2014 at 10:53 #5152
Anders SøborgKeymasterHi 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
December 30, 2014 at 12:03 #5155
Jacek SParticipantHi
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 Jacek S.
December 30, 2014 at 12:25 #5158
Anders SøborgKeymasterHi 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
December 30, 2014 at 12:29 #5159
Anders SøborgKeymasterHi again
Why do you have a return value in the post handler code? Return values should only be used for GET
/Anders
December 30, 2014 at 12:40 #5160
Jacek SParticipantHi,
Yes, I forgot to remove this. I will do more tests today.
Jacek
December 30, 2014 at 18:26 #5162
Jacek SParticipantHi 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.December 30, 2014 at 19:32 #5164
Jacek SParticipantHi 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
December 30, 2014 at 19:55 #5165
Anders SøborgKeymasterSweeeeet – what about the startup time -:)
/Anders
December 30, 2014 at 20:03 #5166
Anders SøborgKeymasterHi 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
-
AuthorPosts
You must be logged in to reply to this topic.
Follow