NeonMika.Webserver - Page 10 - Project Showcase - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

NeonMika.Webserver

webserver web server neonmika internet web server http sd xml json

  • Please log in to reply
213 replies to this topic

#181 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 01 February 2014 - 09:25 PM

Hmm.. Just tried it, it works for me...

Just created a file called BData.txt by using the command http://192.168.0.200...th=SD/BData.txt

The you can access the SD-card by writing htttp://192.168.0.200/SD or directly the file by writing http.//192.168.0.200/SD/BData.txt

 

The workflow is as follows:

The server checks if the incoming request is POST.

If so, the PostToSdWrite saves the file in the lastPOST-file

After that, the normal "Request handling" starts... This happens by looking at the parameter, in our case "upload"...

This triggers the method Upload(...) in the Server.cs (line 675)... As you can see there, it creates the directory if it doesn't exists and opens the file with FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);

FileMode.Create should automatically create the file if it doesn't exist (it does this in my case, didn't have a BData.txt before uploading it)

 

Attached you can find the "tool" i use for uploading, sorry, I don't have a web-page that does it... As I mentioned before I think its important to use request.ContentType = "application/x-www-form-urlencoded";

Sorry that I cannot give you input on how to handle this in html-code, since I'm only a desktop-dev and have nothing to do with web-development *shame on me* :P

 

Greets, Markus

Attached Files


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#182 CT1

CT1

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 03 February 2014 - 01:15 PM

Hi Markus

Eureka!  Success!

I couldn't figure out how you were getting data in your file with just your upload command  ....  then it hit me.

The data gets uploaded to lastPost and then the /upload?path= command copies the data to the appropriate filename.

And YES it also creates new files on the SD card.  Your last post was very informative and it made the light bulb go on for me.

 

I just dropped in some quick code in my javascript to verify and IT WORKS.

Thanks again



#183 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 05 February 2014 - 08:05 PM

Hey CT1, that's great to hear!

I'm glad that my webserver and my work can help the community.

I also have been away from my code for some time, so I also couldn't help without looking at it (and fixing it :P)

 

 

May I ask you what you are planning to build uppon NeonMika.Webserver? Do you plan to publish some blog / post on netduino.com on your project?

I'm always interested in related project :)

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#184 buddy1313

buddy1313

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationMichigan, USA

Posted 04 March 2014 - 01:45 PM

Hello Markus,

 

Thank you very much for sharing your library. I've been learning a lot about networking and c# code.

 

I'm trying to modify your library so that the static IP address of the netduino could be changed through the browser. I'm still new to c# and networking code in general, so this is proving quite difficult for me. I've tried adding the following expansion method to the server class and adding it to the server via your AddResponse method.

public void newIP(Request e, Hashtable h)
        {
            String ipAddress = "";
            String subnetMask = "";
            String gateWay = "";
            if (e.GetArguments.Contains("ip") == true)
            {
                if (e.GetArguments.Contains("subnet") == true)
                {
                    if (e.GetArguments.Contains("gateway") == true)
                    {
                        ipAddress = "" + e.GetArguments["ip"];
                        subnetMask = "" + e.GetArguments["subnet"];
                        gateWay = "" + e.GetArguments["gateWay"];
                    }
                }
            }
            h.Add("ip", ipAddress);
            h.Add("subnet", subnetMask);
            h.Add("gateway", gateWay);
            var interf = NetworkInterface.GetAllNetworkInterfaces()[0];
            interf.EnableStaticIP(ipAddress, subnetMask, gateWay);
        }

After sending the server the following:

 

http://netduinoplus/...eway=10.4.100.1

 

I get two System.IO.IOExceptions. Hopefully what I would like to accomplish is pretty easy and I'm just misguided.

 

Thanks again for this awesome library!

 

-Michael



#185 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 04 March 2014 - 06:39 PM

Hi Michael,

first of all thanks for the kind words. I'm always happy when this project can help somebody to learn something new :)

 

Now the bad news: I cannot see what should be wrong with your code... I will have to grab my netduino and try it by myselft...

 

One thing i can tell you about C#:

ipAddress = "" + e.GetArguments["ip"];
subnetMask = "" + e.GetArguments["subnet"];
gateWay = "" + e.GetArguments["gateWay"];

could be replaced by

ipAddress = e.GetArguments["ip"].ToString();
subnetMask = e.GetArguments["subnet"].ToString();
gateWay = e.GetArguments["gateWay"].ToString();

This is more "best practice" and more readable. When concatinating a string with another "non-string"-object (in this case of type object I think), ToString() automatically gets called on the second object (That why you can write string foo = "myblablavariable" + 14; and don't have to write string foo = "myblablavariable" + (14).ToString())

 

Probably if you could post the exceptions thrown by a call of the method I could help you more.

 

This was also my first big project on networking and so I can't tell you if you have to do something before calling interf.EnableStaticIP(ipAddress, subnetMask, gateWay);

If we can't work it out I'm pretty sure Chris Walker can help us out, he's far more levels above me when it come to Micro Framework :P

 

A last question from my side: Why do you need the method?

When starting the server you can set the IP like in the following example:

Server WebServer = new Server(PinManagement.OnboardLED, 80, false, "192.168.0.200", "255.255.255.0", "192.168.0.1", "NETDUINOPLUS");

Just curious :)

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#186 buddy1313

buddy1313

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationMichigan, USA

Posted 05 March 2014 - 01:20 PM

Thank you for your reply and assistance Markus. I added a Debug print at the beginning of my newIP method like so to see if it was even getting called:

  public void newIP(Request e, Hashtable h)
        {
            Debug.Print("newIP was called");
            String ipAddress = "";
            String subnetMask = "";
            String gateWay = "";

And it wasn't. This is the output I got after using the above URL, including the exceptions you wanted to see:

 

Client connected
URL: newIP
Final byte count: 506
 
A first chance exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll
A first chance exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll
Sent 404 Not Found
Reqeust finished
 
I think there may be a chance I don't have the library set up properly to make modifications to it. As I said before I'm still new to c#, visual studio, and network code. I have two projects set up, one from your WebserverExecutable and one from your Webserver. I modify the code in Webserver, rebuild it after the changes I make, then I delete the reference to NeonMika.Webserver in the WebserverExecutable project and remake the reference to the newly rebuilt .dll file for the Webserver. Is that the proper way to make the changes I'm trying to implement to the library? It feels like I'm missing something.
 
I want to be able to change the IP of my netduino over the network so it can be managed remotely. It is actually being potentially used on a pretty large scale project for my employer. If I can get the devices to perform as needed, there may be as many as 100 netduinos deployed in one of our shops. Each will be attached to an RFID reader and will be hooked up to a controller for a manufacturing cell that makes parts. Our operators will have an RFID card given to them that will be read by the netduino to have the machine select the appropriate die set for their part and will tell the netduino how to collect data for the particular parts we're making. We need to be able to configure almost everything about the netduino remotely, as making changes to so many units locally would be tedious. It's a pretty cool project! I'd be more than happy to keep you up to date on how it turns out.


#187 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 05 March 2014 - 01:56 PM

So i just looked up some older posts and I think this one could help you: http://forums.netdui...ge-8#entry44189

 

There is the "default way" how to start a project using NeonMika.Webserver.

 

I'm pretty sure it has to do with the webserver-code. Have you tried to debug Server.cs? Setting a breakpoint in WaitingForRequest and stepping through the code with F5, F10 and F11 enables you to inspect the code in real detail (especially F11).

It would be very interesting at which point the error occurs.

Sorry that I cannot point out more at this point. but if you find the code-line on which the error accurs I can try to help further :)

 

You project sounds really cool! Would be really nice to see NeonMika.Webserver participate in such a big project. Please keep me updated how it works out! :)


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#188 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 10 March 2014 - 07:12 PM

Hi 

 

Just wondered if this could work with the MiP library in order to use it on N GO! and standard netduino 1?

 

Also would it be possible to use MQTT with it?

 

Many thanks

 

Andy



#189 buddy1313

buddy1313

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationMichigan, USA

Posted 12 March 2014 - 12:42 PM

Hello again Markus,

 

I had the opportunity to work on my project again this morning. I set up a project as described in the post you linked to me, and now I can tell my newIP method is getting called. The request finishes and throws no errors, however the IP address doesn't change. Any idea what to do next?

 

Here's what my method currently looks like:

public void newIP(Request e, Hashtable h)
        {
            Debug.Print("newIP was called");
            String ip = "";
            String subnetMask = "";
            String gateWay = "";
            if (e.GetArguments.Contains("ip"))
            {
                if (e.GetArguments.Contains("subnet"))
                {
                    if (e.GetArguments.Contains("gateway"))
                    {
                        ip = e.GetArguments["ip"].ToString();
                        subnetMask = e.GetArguments["subnet"].ToString();
                        gateWay = e.GetArguments["gateway"].ToString();
                        Debug.Print(ip + " " + subnetMask + " " + gateWay);
                    }
                }
            }
            var interf = NetworkInterface.GetAllNetworkInterfaces()[0];
            interf.EnableStaticIP(ip, subnetMask, gateWay);

            NameService nameService = new NameService();
            nameService.AddName("NETDUINOPLUS", NameService.NameType.Unique, NameService.MsSuffix.Default);
        }

I just put those last two lines with the NameService method in. I wasn't sure if they'd be necessary or not. Here's the response I get from my debug output:

 

Client connected
URL: newIP
Final byte count: 421
 
newIP was called
10.4.20.50 255.255.0.0 10.4.100.1
Reqeust finished


#190 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 12 March 2014 - 04:18 PM

Hi Michael, I'm sorry, but I don't know much about the network-setting possibilities and methods of the N+. As recommended above I think it would be a good idea to contact Chris Walker or open another thread in the N+ Forum, I'm sure someone else can give you a hint. :)

I'm without internet this from now to monday, so I cannot look it up for you.

But I hope you get it working! :)

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#191 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 12 March 2014 - 04:25 PM

Hi 

 

Just wondered if this could work with the MiP library in order to use it on N GO! and standard netduino 1?

 

Also would it be possible to use MQTT with it?

 

Many thanks

 

Andy

 

Hi Andy!

I don't own a N GO! nor a standard netduino, so I don't know about the MiP library.

I also don't really know how the MQTT works, just saw some projects on here. I don't think that they use the default HTTP-header (which is eg. added when calling the netduino via the browser), so I don't think that it would work without adjusting the server. But I could imagine that a little hacking could work out to combine NeonMika.Webserver with one of the MQTT-projects ;) Nothing is impossible :P

 

Sorry that I can't help you more.

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#192 cyberpex

cyberpex

    New Member

  • Members
  • Pip
  • 8 posts

Posted 14 March 2014 - 02:48 PM

Hi Markus!

I have Visual Studio 2010 Pro, and i can´t open neonmika webserver 1.2 executable in VS2010.

 

I make a new project in VS2010 with framework and start webserver en Program.cs. I get an uncontrolled exception: 'System.Net.Sockets.SocketException' en Microsoft.SPOT.Net.dll 

That occurrs when NameService.cs is running on line:

int count = socket.ReceiveFrom(buffer, ref remoteEndPoint); // Blocking call, returns 0 when socket is closed

 

Then, I try change VS project .sln to version 11 and VS2010, but i get same exception.

 

You know how to run neonmika in VS2010?

 

Thanks!

 



#193 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 15 March 2014 - 12:00 PM

I cannot tell if the project works in VS 2010, I developed it in VS 2012.

You could try to install VS 2012 express, this should be freely available for everybody. At least I think so, as a student every microsoft development tool is free for me :P

I only have 2012 and 2013 installed at the moment, so I'm sorry that I cannot test it at the moment. Please let us know if and how you get it working :)

 

Have a nice sunday, Markus :)


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#194 cyberpex

cyberpex

    New Member

  • Members
  • Pip
  • 8 posts

Posted 15 March 2014 - 07:14 PM

Thanks Markus

 

With VS2012 I need Firmware v4.2.0.1, .NET micro framwork v4.2 and netduino SDK v4.2?

(just checking)

 

Thanks again!



#195 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 20 March 2014 - 12:08 PM

Yes, NeonMika.Webserver is developed for firmware 4.2 :)

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#196 cyberpex

cyberpex

    New Member

  • Members
  • Pip
  • 8 posts

Posted 22 March 2014 - 06:19 PM

Yes, NeonMika.Webserver is developed for firmware 4.2 :)

 

Greets, Markus

 

Thanks Markus!
 
Do you have tried Serial Communication with NeonMika.Webserver?
I tried, without success


#197 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 22 March 2014 - 08:50 PM

i've never tried tried it, but i think it should be possible.

Could you explain a little bit more what you would like to achive?

Probably i (or the communtity) could try to help a little more :)

 

Greets, Markus :)


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#198 cyberpex

cyberpex

    New Member

  • Members
  • Pip
  • 8 posts

Posted 23 March 2014 - 01:47 PM

I want send serial commands, like "R1D\r\n" and process the reply (like "1FFFFF\r\n")

 

I tried with this code, and works, but when i put it in NeonMika's project fault at serial.Open()M

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using System.IO;
using System.IO.Ports;

namespace NetduinoPlusApplication1
{
    public class Program
    {
        public static void Main()
        {
            string comando = "R10\r\n";
            byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(comando);

            SerialPort serial = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
            serial.Open();
            while (true)
            {
                // Get full date & time
                serial.Write(utf8Bytes, 0, utf8Bytes.Length);
                getResponse(serial);
         
                Thread.Sleep(1000);
            }
        }

        private static void getResponse(SerialPort serial)
        {
            String response = "";
            while (serial.BytesToRead > 0)
            {
                byte[] buf = new byte[1];
                serial.Read(buf, 0, 1);
                if (buf[0] != 0x0A)
                {
                    response += (char)buf[0];
                }
                else
                {
                    Debug.Print(response);
                    break;
                }
            }
        }

    }
}



#199 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 23 March 2014 - 04:23 PM

I could imagine that it has something to to with my PinManagement class, you can see it here: https://neonmikawebs...inManagement.cs

 

You could try to exclude this class from the server library.

I think it cannot open a SerialPort on "COM1", because the Pins used by "COM1" are already "reserved" by the static PinManagement class.

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#200 cyberpex

cyberpex

    New Member

  • Members
  • Pip
  • 8 posts

Posted 23 March 2014 - 05:56 PM

Correct!
I already did it!
(just came to reply myself)
 
I did some minor changes (delete D1 y D0 pin references) in your PinManagement class and works!
 
Thanks for help!






Also tagged with one or more of these keywords: webserver, web server, neonmika, internet, web, server, http, sd, xml, json

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.