Hello all,
I’ve created a strange little thing that captures an image, publishes it to the web, then does a google image search by url and returns the first match.
you can one result here ( http://justincouchdesign.com/gadgeteer/images/gimgcurldump1358536831.jpg.html ).
Eventually I would like to return this result back to the Gadgeteer display.
But the problem. Two days ago, this code worked. You can see the results in the link. But now my code won’t even capture a picture, much less send it to the web so I can work on getting some info back. I’ve put debugs in to check if the camera is ready. I’m just not sure what is bogging down the program. When I run it, everything starts, the wifi connects, it reads a button pressed event when the button is pressed and then it just stops. No errors, just silence. I’ll attach the code and hopefully someone can point out something trivial that I’m missing.
As an aside, after the ProgramStarted function runs I get a message “The thread ‘’ (0x3) has exited with code 0 (0x0).” Is this bad? What does it mean? Does it have to do with the wifi?
namespace JCgoogleCamera2
{
public partial class Program
{
string WIFINETWORK = "your_wifi_network";
string WIFIPASSWORD = "your_wifi_password";
void ProgramStarted()
{
Debug.Print("Program Started");
button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
camera.PictureCaptured += new Camera.PictureCapturedEventHandler(camera_PictureCaptured);
camera.CameraConnected += new Camera.CameraConnectedEventHandler(camera_CameraConnected);
startWifi();
Debug.Print("end of Program Started");
}
void camera_CameraConnected(Camera sender)
{
if (camera.CameraReady) { Debug.Print("camera ready."); }
}
void button_ButtonPressed(Button sender, Button.ButtonState state)
{
Debug.Print("button pressed");
//multicolorLed.TurnBlue();
Debug.Print("camera is ready: " + camera.CameraReady);
if (camera.CameraReady)
{
Debug.Print("starting to take picture");
camera.TakePicture();
}
else { Debug.Print("camera not ready"); }
Debug.Print("end of button pressed");
}
void camera_PictureCaptured(Camera sender, GT.Picture picture)
{
Debug.Print("picture captured");
//multicolorLed.TurnGreen();
display_T35.SimpleGraphics.DisplayImage(picture, 0, 0);
postPictureToWeb(picture);
}
void postPictureToWeb(GT.Picture picture)
{
GT.Networking.POSTContent postcontent = new POSTContent();
postcontent = GT.Networking.POSTContent.CreateBinaryBasedContent(picture.PictureData);
Debug.Print("posting");
GT.Networking.HttpRequest postreq = HttpHelper.CreateHttpPostRequest("php_save_file", postcontent, "image/bmp");
postreq.ResponseReceived += new HttpRequest.ResponseHandler(postreq_ResponseReceived);
postreq.SendRequest();
}
void postreq_ResponseReceived(HttpRequest sender, HttpResponse response)
{
Debug.Print("Response Received");
string filename = response.Text;
Debug.Print(filename);
Debug.Print(response.StatusCode);
sendCurlToWeb(filename);
}
void sendCurlToWeb(string filename)
{
Debug.Print("curling");
string phpadd = "php_curl_file" + filename;
Debug.Print("sending curl req to: " + phpadd);
GT.Networking.HttpRequest curlreq = WebClient.GetFromWeb(phpadd);
curlreq.ResponseReceived += new HttpRequest.ResponseHandler(curlreq_ResponseReceived);
curlreq.SendRequest();
}
void curlreq_ResponseReceived(HttpRequest sender, HttpResponse response)
{
Debug.Print("curl response received");
string curlresponsetxt = response.Text;
Debug.Print(curlresponsetxt);
}
void startWifi()
{
Debug.Print("Starting Wifi");
wifi_RS21.Interface.Open();
wifi_RS21.Interface.NetworkInterface.EnableDhcp();
GHI.Premium.Net.NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);
wifi_RS21.Interface.WirelessConnectivityChanged += new GHI.Premium.Net.WiFiRS9110.WirelessConnectivityChangedEventHandler(Interface_WirelessConnectivityChanged);
try
{
Debug.Print("scanning for network");
GHI.Premium.Net.WiFiNetworkInfo[] ScanResp = wifi_RS21.Interface.Scan(WIFINETWORK);
if (ScanResp != null && ScanResp.Length > 0)
{
Debug.Print("connecting...");
wifi_RS21.Interface.Join(ScanResp[0], WIFIPASSWORD);
//multicolorLed.BlinkRepeatedly(GT.Color.Orange);
}
else
{
//multicolorLed.BlinkRepeatedly(GT.Color.Red);
Debug.Print("failed");
}
}
catch (Exception e)
{
Debug.Print("unable to find network.");
//multicolorLed.BlinkRepeatedly(GT.Color.Purple);
}
}
void Interface_WirelessConnectivityChanged(object sender, GHI.Premium.Net.WiFiRS9110.WirelessConnectivityEventArgs e)
{
if (e.IsConnected)
{
//multicolorLed.TurnGreen();
Debug.Print("wifi connected");
}
}
}
}