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.

Graham.fry

Member Since 30 Dec 2012
Offline Last Active Aug 19 2014 02:34 PM
-----

Posts I've Made

In Topic: Not able to change network settings

17 October 2013 - 12:54 PM

I know it is not the exact answer you are looking for but if I need to use a fixed IP I get my netduino to run this line at the when it boots up.

 

Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableStaticIP("192.168.1.122", "255.255.255.0", "192.168.1.62");

 

 

by using this I don't need to configure each device before using I just change the IP I want to change.


In Topic: A first chance exception of type 'System.InvalidOperationException' o...

03 September 2013 - 08:03 AM

For anybody that cares

 

If you having a problem using the hardware DLL in 4.3 (with servos) you need to uninstall all 4.3 sdk's and reinstall 4.2

 

This fixed my problem


In Topic: Date from netduino plus

06 August 2013 - 12:03 PM

Here is the code to get time from the internet using netduino

 

using System;

using System.Net;

using System.Net.Sockets;

using Microsoft.SPOT;

using System.Threading;

namespace GetTime

{

public class Program

{

public static void Main()

{

var result = UpdateTimeFromNtpServer("time.nist.gov", 2); // gmt + 2

Debug.Print(result ? "Time successfully updated" : "Time not updated");

while (true)

{

Debug.Print("netduino Time is: " + DateTime.Now.ToString());//TimeClient.LocalDate.ToString());

Thread.Sleep(60000);

}

//return result;

}

public static bool UpdateTimeFromNtpServer(string server, int timeZoneOffset)

{

try

{

var currentTime = GetNtpTime(server, timeZoneOffset);

Microsoft.SPOT.Hardware.Utility.SetLocalTime(currentTime);

return true;

}

catch

{

return false;

}

}

private static DateTime GetNtpTime(String timeServer, int timeZoneOffset)

{

// Find endpoint for TimeServer

var ep = new IPEndPoint(Dns.GetHostEntry(timeServer).AddressList[0], 123);

// Make send/receive buffer

var ntpData = new byte[48];

// Connect to TimeServer

using (var s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))

{

// Set 10s send/receive timeout and connect

s.SendTimeout = s.ReceiveTimeout = 10000; // 10,000 ms

s.Connect(ep);

// Set protocol version

ntpData[0] = 0x1B;

// Send Request

s.Send(ntpData);

// Receive Time

s.Receive(ntpData);

// Close the socket

s.Close();

}

const byte offsetTransmitTime = 40;

ulong intpart = 0;

ulong fractpart = 0;

for (var i = 0; i <= 3; i++)

intpart = (intpart << 8) | ntpData[offsetTransmitTime + i];

for (var i = 4; i <= 7; i++)

fractpart = (fractpart << 8) | ntpData[offsetTransmitTime + i];

ulong milliseconds = (intpart * 1000 + (fractpart * 1000) / 0x100000000L);

var timeSpan = TimeSpan.FromTicks((long)milliseconds * TimeSpan.TicksPerMillisecond);

var dateTime = new DateTime(1900, 1, 1);

dateTime += timeSpan;

var offsetAmount = new TimeSpan(timeZoneOffset, 0, 0);

var networkDateTime = (dateTime + offsetAmount);

return networkDateTime;

}

}

}


In Topic: How to read data html with web server?

06 August 2013 - 11:44 AM

Hi

[font="calibri;"]In my request I have limited my response to 2 characters and my var indicator is light= this works every time[/font]

 
 //Get request
  byte[] buffer = new byte[bytesReceived];
  int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);
  string request = new string(Encoding.UTF8.GetChars(buffer));
  Debug.Print(request);

  //int countof = request.IndexOf("light="); //for my code
 int countof = request.IndexOf("user=");
  countof = countof + 6;
  //var s = request.Substring(countof, 2); //for my code

 

You may need to add the following and it may need some tweeking

 

 int noChatTotext = X //(this is the number of char to the end of user= it should constant)
 int lengthOfrequest = request.length(); //calculate the length of the hole request sent.
 int noCharToGet =  lengthOfrequest - noChatTotext; //the length of the text you want
 var s = request.Substring(countof, noCharToGet); //S will be the text you want


In Topic: Hello World Webservice where to start Visual Studio 2012

05 July 2013 - 06:09 AM

Hi all

 

I have installed the SDK and upgraded the board to 4.2.2.2

 

Under microframwork I get

  Class

  Device Emulator

  Windows Application

 

I can build a blinky application and control RGB's etc. that is using the console application should I just us the console application to build the webservice.


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.