Transferring images from SerCam to my laptop using C#

Hello,

I am trying to transfer the token images from Camera module to my laptop using .Net gedgeteer. I am starting by trying transfer just text to see if this can be working. If you have the direct code , I would appreciate it.

Otherwise, my question is for now http://ipaddressdevice/hello doesn’t give a response on browser. The browser keeps loading but never retrieves anything. Tried it using postman as well nothing comes through. Pinging the device works. The code seems to be correct I don’t know why it’s not retrieving the hello world HTML.

using Microsoft.SPOT;

using Gadgeteer.Networking;

using GT = Gadgeteer;

using GTM = Gadgeteer.Modules;

using Gadgeteer.Modules.GHIElectronics;

using System.Threading;

namespace IntelSight

{

public partial class Program

{

    GT.Networking.WebEvent sayHello;

    Gadgeteer.Networking.WebEvent takePicture;

    Gadgeteer.Networking.WebEvent seePicture;

    // This method is run when the mainboard is powered up or reset.  

    void ProgramStarted()

    {

        GT.Timer t = new GT.Timer(1000);

        t.Tick += new GT.Timer.TickEventHandler(t_Tick);

        t.Start();

    }

    void t_Tick(GT.Timer timer)
    {
       timer.Stop();

        // to use hold the network to connect to

        GHI.Premium.Net.WiFiNetworkInfo[] info = null;

        // use the router's DHCP server to set my network info
        if (!wifi_RS21.Interface.IsOpen)

        wifi_RS21.Interface.Open();

        if(!wifi_RS21.Interface.NetworkInterface.IsDhcpEnabled)

        wifi_RS21.Interface.NetworkInterface.EnableDhcp();

        wifi_RS21.Interface.NetworkInterface.EnableDynamicDns();
        wifi_RS21.Interface.NetworkAddressChanged += Interface_NetworkAddressChanged;

        wifi_RS21.Interface.WirelessConnectivityChanged+=Interface_WirelessConnectivityChanged;

        info = wifi_RS21.Interface.Scan();

        for (int i = 0; i < info.Length; i++)

        {

            if (info[i].SSID == "Connectify-test")

            {

                wifi_RS21.Interface.Join(info[i], "abdi1990");

                break;

            }

        }

        Thread.Sleep(-1);      

       

    }

    private void Interface_WirelessConnectivityChanged(object sender, GHI.Premium.Net.WiFiRS9110.WirelessConnectivityEventArgs e)

    {

        Debug.Print("RSSI: -" + e.NetworkInformation.RSSI + "dB");

    }

    void Interface_NetworkAddressChanged(object sender, EventArgs e)

    {

        Debug.Print(wifi_RS21.Interface.NetworkInterface.IPAddress + "");

        if (wifi_RS21.Interface.NetworkInterface.IPAddress!="0.0.0.0")

        {

            WebServer.StartLocalServer(wifi_RS21.Interface.NetworkInterface.IPAddress, 80);

            sayHello = WebServer.SetupWebEvent("hello");

            sayHello.WebEventReceived += new WebEvent.ReceivedWebEventHandler(sayHello_WebEventReceived);

           // wifi_RS21.Interface.Disconnect();

        }

    }

    void sayHello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)

    {

        string content = "<html><body><h1>Hello World!!</h1></body></html>";

        byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content);

        responder.Respond(bytes, "text/html");

    }
}

}

please edit your post and use the CODE tags as that will make it easier to read your code. Can you also clarify what you’re talking about the images and SerCam (the title) but the body talks about web server and hello world? What problem are you trying to solve?

ok, so another thing or two.

You haven’t talked about what mainboard you’re using; please clarify.
You have debug.print scattered through the code, but you don’t show us the output; please do.
You have used GHI.Premium. What firmware and SDK version are you using, and why? Is there any reason you’re not using the latest, because there may have been issues addressed in those firmware versions.

@ Brett -

Hello Brett,

Thanks on your reply.

I am trying send all captured images from SerCam module to my laptop to process them. I am using spider mainboard and framework 4.2. When I was looking up the way I found some articles saying that I need to setup the webserver in order to transfer my images to the laptop. So, I started setting up the web server, then try to transfer a text instead of images just a trial.

However, the aim is just to send the captured images to my laptop. If you have any easier code, that will be more than nice.

Wafa

@ Brett -

Again Brett,

I am not using 4.3 because I am using seeed GPS in my system; seeed GPS can’t work on 4.3 . GHI GPS is discontinued for some issues . Do you have any ideas? I would rather upgrade to 4.3 but the problem is the GPS.

Discontinued, yes, but it doesn’t mean it will not work with the latest firmware…

The 4.3 source code for the Seeed GPS Module is available here. [url]https://bitbucket.org/ghi_elect/gadgeteer/src/eba1405f769bd03e7241b5ca8cc305d5a4ba4be1/Modules/GHIElectronics/GPS/?at=master[/url].

And as @ Brett indicated, you should update to the latest firmware which solved problems with the 4.2 version.

There are several places where you could be having a problem. I suggest you start with a new project, and add functionality one step at a time.

  1. Initialize WIFi and associate with access point. make sure you have an IP address.
  2. Add a web server by adding a working example. verify it works
  3. Add you web processing and verify it works.
  4. Integrate camera.

ETC…

By debugging in small steps, you can find where you are having a problem.

1 Like

So setting a webserver and getting that to be responsive is a great first step in getting a webserver to transfer an image as part of a web request. But that doesn’t mean that this is the only way to get an image file from device to PC. What connections do you have? For example, if you don’t expect to have a direct connection between the device and a PC when in normal use, then absolutely you should consider wifi and a webserver, but if you have a USB Serial connection always at your disposal, then you could just use that and transfer the content.

On the 4.2 vs 4.3, I would definitely move to 4.3. I recall issues in 4.2 timeframe, and in wifi and web server areas, so getting to 4.3 means you eliminate those. If the GPS is the only thing stopping you, then absolutely get the code that’s been pointed out to you - or even just look at the 4.2 code and port that yourself as GPSes are pretty simple beasts. Do you really have the GPS in this project though, as I can’t really see a wifi, camera, PC setup needing a GPS? :slight_smile: Anyway, that should not be an issue that holds you back.

And still fix your code tags. open code tag before your code, and close code tag after. Nobody can even copy that code to try out, so you really need to fix that if you want anyone else to provide valuable feedback

As we pointed out a few months ago you can use the GHI 4.3 driver with your Seed GPS

[url]https://www.ghielectronics.com/community/forum/topic?id=6927&page=12#msg219686[/url]

@ Brett -

This is a part of my project. Yes, I will need GPS. I will consider your advice and try to upgrade to 4.3. I will try to tag the code.

Thanks
Wafa

@ Brett -

using Microsoft.SPOT;

 using Gadgeteer.Networking;

 using GT = Gadgeteer;

 using GTM = Gadgeteer.Modules;

 using Gadgeteer.Modules.GHIElectronics;

 using System.Threading;

 namespace IntelSight

 {

 public partial class Program

 {

 GT.Networking.WebEvent sayHello;

 Gadgeteer.Networking.WebEvent takePicture;

 Gadgeteer.Networking.WebEvent seePicture;

 // This method is run when the mainboard is powered up or reset. 

 void ProgramStarted()

 {

 GT.Timer t = new GT.Timer(1000);

 t.Tick += new GT.Timer.TickEventHandler(t_Tick);

 t.Start();

 }

 void t_Tick(GT.Timer timer)
 {
 timer.Stop();

 // to use hold the network to connect to

 GHI.Premium.Net.WiFiNetworkInfo[] info = null;

 // use the router's DHCP server to set my network info
 if (!wifi_RS21.Interface.IsOpen)

 wifi_RS21.Interface.Open();

 if(!wifi_RS21.Interface.NetworkInterface.IsDhcpEnabled)

 wifi_RS21.Interface.NetworkInterface.EnableDhcp();

 wifi_RS21.Interface.NetworkInterface.EnableDynamicDns();
 wifi_RS21.Interface.NetworkAddressChanged += Interface_NetworkAddressChanged;

 wifi_RS21.Interface.WirelessConnectivityChanged+=Interface_WirelessConnectivityChanged;

 info = wifi_RS21.Interface.Scan();

 for (int i = 0; i < info.Length; i++)

 {

 if (info[i].SSID == "Connectify-test")

 {

 wifi_RS21.Interface.Join(info[i], "abdi1990");

 break;

 }

 }

 Thread.Sleep(-1); 



 }

 private void Interface_WirelessConnectivityChanged(object sender, GHI.Premium.Net.WiFiRS9110.WirelessConnectivityEventArgs e)

 {

 Debug.Print("RSSI: -" + e.NetworkInformation.RSSI + "dB");

 }

 void Interface_NetworkAddressChanged(object sender, EventArgs e)

 {

 Debug.Print(wifi_RS21.Interface.NetworkInterface.IPAddress + "");

 if (wifi_RS21.Interface.NetworkInterface.IPAddress!="0.0.0.0")

 {

 WebServer.StartLocalServer(wifi_RS21.Interface.NetworkInterface.IPAddress, 80);

 sayHello = WebServer.SetupWebEvent("hello");

 sayHello.WebEventReceived += new WebEvent.ReceivedWebEventHandler(sayHello_WebEventReceived);

 // wifi_RS21.Interface.Disconnect();

 }

 }

 void sayHello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)

 {

 string content = "<html><body><h1>Hello World!!</h1></body></html>";

 byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content);

 responder.Respond(bytes, "text/html");

 }
 }

 } 

@ welmanna@ my.bridgeport.edu - Check the timer object that you are creating in the ProgramStarted method. It goes out of scope when you exit the method, and may never be firing…

where’s the debug output when you run it? That will also help demonstrate if the timer fired and it joined the network

@ Brett - I am Including the code, output and screenshot of my output. Please your advice.

using System;

using System.Collections;

using System.Threading;

using Microsoft.SPOT;

using Microsoft.SPOT.Presentation;

using Microsoft.SPOT.Presentation.Controls;

using Microsoft.SPOT.Presentation.Media;

using Microsoft.SPOT.Presentation.Shapes;

using Microsoft.SPOT.Touch;




using Gadgeteer.Networking;

using GT = Gadgeteer;

using GTM = Gadgeteer.Modules;

using Microsoft.SPOT.Net.NetworkInformation;







namespace WebSer

{

    public partial class Program

    {

        GT.Networking.WebEvent sayHello;

        GT.Timer t;

        void ProgramStarted()

        {

            t = new GT.Timer(1000);

            t.Tick += new GT.Timer.TickEventHandler(t_Tick);

            t.Start();

        }




        private void t_Tick(GT.Timer timer)

        {

            t.Stop();

            if (!wifi.NetworkInterface.Opened)

                wifi.NetworkInterface.Open();

            if (!wifi.NetworkInterface.IsDhcpEnabled)

                wifi.NetworkInterface.EnableDhcp();

            wifi.NetworkInterface.NetworkInterface.EnableDynamicDns();




            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;

            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;

           wifi.NetworkInterface.Join("Connectify-test", "abdi1990");

           while (true)

            {

                string ipaddress = wifi.NetworkInterface.IPAddress;

                Debug.Print(ipaddress);




                if (ipaddress != "0.0.0.0") break;




                Thread.Sleep(1000);

            }

            Thread.Sleep(-1);   

        }




        private void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)

        {

            Debug.Print("CHANGED");




        }




        private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)

        {

            Debug.Print(wifi.NetworkInterface.IPAddress+"from event");

            if (wifi.NetworkInterface.IPAddress != "0.0.0.0")

            {

                WebServer.StartLocalServer(wifi.NetworkInterface.IPAddress, 80);

                sayHello = WebServer.SetupWebEvent("hello");

                sayHello.WebEventReceived+=sayHello_WebEventReceived;

                // wifi_RS21.Interface.Disconnect();

            }

        }




        private void sayHello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)

        {

            string content = "<html><body><h1>Hello World!!</h1></body></html>";

            byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content);

            responder.Respond(bytes, "text/html");

        }

    }

}

The output at first when it connects is this

The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Spider version 1.0
The thread ‘’ (0x3) has exited with code 0 (0x0).
0.0.0.0
0.0.0.0
CHANGED

192.168.137.102from event

Web server started at http://192.168.137.102:80/
192.168.137.102
then when I go to http://192.168.137.102:80 it outputs the two additional lines at the end
and displays the default site properly. which I have also attached as picture
The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Spider version 1.0
The thread ‘’ (0x3) has exited with code 0 (0x0).
0.0.0.0
0.0.0.0
CHANGED
192.168.137.102from event
Web server started at http://192.168.137.102:80/
192.168.137.102
The thread ‘’ (0x7) has exited with code 0 (0x0).
The thread ‘’ (0x8) has exited with code 0 (0x0).

then if go to http://192.168.137.102:80/hello nothing happens the browser keeps loading and outputs two more things at the bottom

The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Spider version 1.0

The thread ‘’ (0x3) has exited with code 0 (0x0).

0.0.0.0

0.0.0.0

CHANGED

192.168.137.102from event

Web server started at http://192.168.137.102:80/

192.168.137.102

The thread ‘’ (0x7) has exited with code 0 (0x0).

The thread ‘’ (0x8) has exited with code 0 (0x0).

The thread ‘’ (0x9) has exited with code 0 (0x0).

The thread ‘’ (0xa) has exited with code 0 (0x0).
So the default http://192.168.137.102:80 works but doesnot http://192.168.137.102:80/hello

add debug.print to your “hello” webevent and see if it’s actually called when you hit the URL.

so there’s now so much more info. We can see how you’ve established the network and started the webserver. So much simpler to diagnose when we have a better picture.

@ Brett - I added debug.print(“event recieved”) to the sayHello_WebEventReceived event handler but nothing prints when i go to http://192.168.137.102:80/hello.

then we’ve established where your problem is. The Webserver isn’t receiving your request, or isn’t parsing it and calling that handler.

@ welmanna@ my.bridgeport.edu - Did you read about the bug in Gadgeteer webserver and did you notice that in the GHI example the Webserver was started in a separate thread?
https://www.ghielectronics.com/downloads/Gadgeteer/NET_Gadgeteer_for_beginners.pdf

1 Like

@ Roschmi, thanks for pointing out the reference. While I didn’t know that off the top of my head, I knew there was a relevant piece of info around, but also didn’t want to give @ welmanna nothing to do - approaching these problems methodically helps build memory muscle and troubleshooting skills that are useful when your own code is involved!

@ Brett - I hope it helps. I didn’t look in-depth if this might be the reason for @ welmanna’s problems.

1 Like