public static void Main() { // Creates a new web session HTTP_Client WebSession = new HTTP_Client(new IntegratedSocket("www.netmftoolbox.com", 80)); // Requests the latest source HTTP_Client.HTTP_Response Response = WebSession.Get("/helloworld/"); // Did we get the expected response? (a "200 OK") if (Response.ResponseCode != 200) { throw new ApplicationException("Unexpected HTTP response code: " + Response.ResponseCode.ToString()); } // Fetches a response header Debug.Print("Current date according to www.netmftoolbox.com: " + Response.ResponseHeader("date")); // Gets the response as a string Debug.Print(Response.ToString()); Trace.Print("Current date according to www.netmftoolbox.com: " + Response.ResponseHeader("date")); Trace.Print(Response.ToString()); Thread.Sleep(Timeout.Infinite); }
public static void WebGet(IndicatorData objIndicatorData) { try { var URL = Settings.ShopTrakTransactionsURL.SetParameters(new string[] { Settings.Job, Settings.Suffix.ToString(), Settings.Operation.ToString() }); Debug.Print("WebGet URL is: " + URL); var objURI = new Uri(URL); var webClient = new HTTP_Client(new IntegratedSocket(objURI.Host, (ushort)objURI.Port)); var response = webClient.Get(objURI.AbsolutePath); Debug.Print("Data recieved from URL is:\r\n" + response.ResponseBody); if (response.ResponseCode != 200) // Did we get the expected response? (a "200 OK") { throw new ApplicationException("HTTP Response: " + response.ResponseCode.ToString()); } else if (response.ResponseBody == "[]") //Does the REST Dataset return empty? { throw new ApplicationException("Nobody punched in that Job."); } ArrayList arrayList = JsonSerializer.DeserializeString(response.ResponseBody) as ArrayList; Hashtable hashtable = arrayList[0] as Hashtable; //get the first row of records //Microsoft.SPOT.Time.TimeService.SetTimeZoneOffset(300); Settings.PrintDateTime = DateTimeExtensions.FromASPNetAjax(hashtable["CurrentDateTime"].ToString()).AddHours(-5);//Central Time Zone has 5 hour offset from UTC Settings.Item = hashtable["item"].ToString(); StringBuilder strBldrEmployees = new StringBuilder(); for (int intCounter = 0; intCounter < arrayList.Count; intCounter++) //iterate over all the rows to get the employees that are punched into the jobs { hashtable = arrayList[intCounter] as Hashtable; strBldrEmployees.Append(hashtable["emp_num"].ToString().Trim() + ","); } strBldrEmployees.Remove(strBldrEmployees.ToString().LastIndexOf(","), 1); //remove the last comma from the string Settings.Employees = strBldrEmployees.ToString(); //Instantiate my label so that I can populate the Format property with the value pulled from the SDCard. var objLabel = new Label(new string[] { Settings.Item, Settings.JobNumber, Settings.OperationNumber.ToString("D3"), Settings.Employees, Settings.PieceCount.ToString("N"), Settings.PrintDateTime.ToString("MM/dd/yy h:mm:ss tt"), Settings.PrintDateTime.ToString("dddd") }); objLabel.LabelFormat = Settings.LabelFormat; Debug.Print("Data written to printer serial port is:\r\n" + objLabel.LabelText); mPrinterSerialPort.WriteString(objLabel.LabelText); } catch (Exception objEx) { Debug.Print("Exception caught in WebGet()\r\n"); Debug.Print(objEx.Message); mMenu.DisplayError(objEx); } }
private string NapkinGet(string path) { try { WiFlySocket socket = new WiFlySocket(NapkinServerName, NapkinServerPort, _wifly); HTTP_Client client = new HTTP_Client(socket); client.Authenticate(DeviceId, DeviceId); HTTP_Client.HTTP_Response response = client.Get(path); return(response.ResponseBody); } catch (Exception ex) { Debug.Print("Exception in PingServer: " + ex.Message); return(null); } }
public static void Main() { try { // Creates a new web session HTTP_Client WebSession = new HTTP_Client(new IntegratedSocket("127.0.0.1", 80)); int index = 1; while (true) { // Requests the latest source HTTP_Client.HTTP_Response Response = WebSession.Post(string.Concat("/restfulsignalrservice/messagebroadcast/broadcast?message=Hello_From_Netdunio.Index", index.ToString())); // Did we get the expected response ? (a "200 OK") if (Response.ResponseCode != 200) { AnimateLed(100); Debug.Print(string.Concat("Unexpected HTTP response code : ", Response.ResponseCode.ToString())); Debug.Print(Response.ToString()); } else { AnimateLed(250); Debug.Print("Successful response "); Debug.Print(Response.ToString()); } if (index == Int32.MaxValue) { index = 1; } else { index++; } } } catch (Exception ex) { Debug.Print(ex.Message); } }
public static void Main() { // There's a 8x8 matrix (64 LEDs) connected to the first SPI bus on the Netduino RgbMatrix matrix = new AdafruitNeoPixel32x8(); matrix.Test0(); NetworkInitializer.NetworkConnected += NetworkConnected; int delayCon = 0; IsConnecting = true; OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); while (IsConnecting) { led.Write(false); // turn on the LED Thread.Sleep(250); // sleep for 250ms led.Write(true); // turn off the LED Thread.Sleep(250); // sleep for 250ms if (delayCon++ == 10) { NetworkInitializer.InitializeNetwork(); } } Debug.Print("Network connected!"); // Creates a new web session HTTP_Client WebSession = new HTTP_Client(new IntegratedSocket("www.netmftoolbox.com", 80)); // Requests the latest source HTTP_Client.HTTP_Response Response = WebSession.Get("/helloworld/"); // Did we get the expected response? (a "200 OK") if (Response.ResponseCode != 200) { throw new ApplicationException("Unexpected HTTP response code: " + Response.ResponseCode.ToString()); } var dateString = Response.ResponseHeader("date"); //Pin1Irq = new IntegratedIRQ(Pins.GPIO_PIN_D1); //Pin1Irq.ID = "D1"; //Pin1Irq.OnStateChange += OnStateChangeHandler; //Pin2Irq = new IntegratedIRQ(Pins.GPIO_PIN_D2); //Pin2Irq.ID = "D2"; //Pin2Irq.OnStateChange += OnStateChangeHandler; var ethernetPower = new OutputPort((Cpu.Pin) 47, false); ethernetPower.Write(false); while (true) { matrix.ScrollToLeftText(1, 0, dateString, 0x130000, 100); Thread.Sleep(500); } }