Example #1
0
        public static void Main()
        {
            //tidy up
            File.Delete("\\SD\\Data.csv");

            try
            {
                //retrive and set device time via NTP
                var networkTime = NtpClient.GetNetworkTime();
                Utility.SetLocalTime(networkTime);

                _macAddress  = GetMAC();
                _blobClient  = new BlobClient(AccountName, AccountKey);
                _tableClient = new TableClient(AccountName, AccountKey);
                _tableClient.CreateTable("netmfdata");

                _onBoardButton = new InterruptPort(Pins.ONBOARD_SW1, true,
                                                   Port.ResistorMode.Disabled,
                                                   Port.InterruptMode.InterruptEdgeHigh);
                _onBoardButton.OnInterrupt += onBoardButton_OnInterrupt;

                _analogInput = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);
            }
            catch (Exception ex)
            {
                Debug.Print("Error setting up Device: " + ex.ToString());
            }

            int counter = 0;

            while (true)
            {
                counter++;
                var data = _analogInput.Read() * 40D;
                _tableClient.AddTableEntityForTemperature("netmfdata", _macAddress, counter.ToString(), DateTime.Now, data, "UK");

                lock (Padlock)
                {
                    using (FileStream fs = File.Open("\\SD\\Data.csv", FileMode.Append, FileAccess.Write))
                    {
                        Debug.Print(data.ToString());
                        var dataBytes = Encoding.UTF8.GetBytes(
                            StringUtility.Format("{0}, {1}, {2}\r\n",
                                                 _macAddress, DateTime.Now.ToString(),
                                                 data)
                            );

                        fs.Write(dataBytes, 0, dataBytes.Length);
                        fs.Flush();
                    }
                }

                Thread.Sleep(1000);
                Debug.Print("Working");
            }
        }
Example #2
0
        internal HttpStatusCode createTable(CloudStorageAccount pCloudStorageAccount, string pTableName)
        {
            //TableClient table = new TableClient(pCloudStorageAccount, caCerts, _timeZoneOffset, _debug, _debug_level);
            TableClient table = new TableClient(pCloudStorageAccount, caCerts, _debug, _debug_level);

            // To use Fiddler as WebProxy include the following line. Use the local IP-Address of the PC where Fiddler is running
            // see: -http://blog.devmobile.co.nz/2013/01/09/netmf-http-debugging-with-fiddler
            if (attachFiddler)
            {
                table.attachFiddler(true, fiddlerIPAddress, fiddlerPort);
            }

            HttpStatusCode resultCode = table.CreateTable(pTableName, TableClient.ContType.applicationIatomIxml, TableClient.AcceptType.applicationIjson, TableClient.ResponseType.dont_returnContent, useSharedKeyLite: false);

            return(resultCode);
        }
 private static void TestCreate()
 {
     _blobClient.CreateTable("ranetmftest");
 }