private static void SetDateTime() { int retryCount = 30; Debug.WriteLine("Waiting for a valid date & time..."); // if SNTP is available and enabled on target device this can be skipped because we should have a valid date & time while ((DateTime.UtcNow.Year < 2018)) { // force update if we haven't a valid time after 30 seconds if (retryCount-- == 0) { Debug.WriteLine("Forcing SNTP update..."); Sntp.UpdateNow(); // reset counter retryCount = 30; } // wait for valid date & time Thread.Sleep(1000); } Debug.WriteLine($"We have valid date & time: {DateTime.UtcNow.ToString()}"); DateTimeAvailable.Set(); }
public void Dispose() { //should dispose of SD and Char display (at least!) #if ORGPAL_THREE palthreeDisplay.Dispose(); palAdcExpBoard.Dispose(); palthreeInternalAdc.Dispose(); palthreeButtons.Dispose(); #endif //System.IO.FileStream -- Dispose?? sendTelemetryTimer.Dispose(); sendShadowTimer.Dispose(); AwsIotCore.MqttConnector.Client.Close(); AwsIotCore.MqttConnector.Client.Dispose(); Sntp.Stop(); _logger = null; }
public static void Main() { // Wait for DHCP while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any) { Thread.Sleep(50); } // Update the current time (since Twitter OAuth API requests require a valid timestamp) DateTime utcTime = Sntp.GetCurrentUtcTime(); Microsoft.SPOT.Hardware.Utility.SetLocalTime(utcTime); // Set up application and user credentials // Visit https://apps.twitter.com/ to create a new Twitter application and get API keys/user access tokens var appCredentials = new OAuthApplicationCredentials() { ConsumerKey = "YOUR_CONSUMER_KEY_HERE", ConsumerSecret = "YOUR_CONSUMER_SECRET_HERE", }; var userCredentials = new OAuthUserCredentials() { AccessToken = "YOUR_ACCESS_TOKEN", AccessTokenSecret = "YOUR_ACCESS_TOKEN_SECRET", }; // Create new Twitter client with these credentials var twitter = new TwitterClient(appCredentials, userCredentials); // Verify the credentials and get the current user's account info try { var currentUser = twitter.GetCurrentUser(); Debug.Print("Authenticated user account: @" + currentUser.ScreenName); } catch (Exception e) { Debug.Print("Could not verify account credentials."); Debug.Print(e.ToString()); } // Send a tweet try { var tweet = twitter.SendTweet("Trying out MicroTweet! #netmf"); Debug.Print("Posted a new tweet with ID: " + tweet.ID); } catch (Exception e) { Debug.Print("Could not send tweet."); Debug.Print(e.ToString()); } // Get recent tweets from the home timeline try { var tweets = twitter.GetHomeTimeline(5); Debug.Print("Recent tweets from your timeline:"); foreach (Tweet tweet in tweets) { Debug.Print(" Tweet from @" + tweet.User.ScreenName + ": \"" + tweet.Text + "\""); } } catch (Exception e) { Debug.Print("Could not retrieve timeline."); Debug.Print(e.ToString()); } // Get recent tweets from a specific user try { var tweets = twitter.GetUserTimeline("twitter"); Debug.Print("Recent tweets from @twitter's timeline:"); foreach (Tweet tweet in tweets) { Debug.Print(" Tweet from @" + tweet.User.ScreenName + ": \"" + tweet.Text + "\""); } } catch (Exception e) { Debug.Print("Could not retrieve timeline."); Debug.Print(e.ToString()); } }