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.
Photo

Writing Temperature Sensor Readings to a file

Visual Studio NetDuino Plus 2 Temperature Sensor File Writing

  • Please log in to reply
No replies to this topic

#1 escallanio

escallanio

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationSydney

Posted 13 May 2014 - 10:15 AM

Hi, 
 
I am extracting temperature reading from temperature sensor DS18B20 built application. I am obtaining values from temperature sensor build on NetDuino plus2. Whenever temperature of room changes, temperature server notify the client. I want to write the observed values from temperature sensor to a file (preferably to excel file) so that i can plot my simulation results. The debug command in the code below print temperature values whenever they are updated. Can anyone help me with code to write the values to an excel spreadsheet or another file.
 
void OnCoAPRequestReceived(CoAPRequest coapReq)
        {
            if (coapReq.MessageType.Value == CoAPMessageType.CON)
            {
                //Extract the temperature..but first, check if the notification is fresh
                //The server sends a 4-digit sequence number
                int newObsSeq = AbstractByteUtils.ToUInt16(coapReq.Options.GetOption(CoAPHeaderOption.OBSERVE).Value);
                if ((lastObsSeq < newObsSeq && ((newObsSeq - lastObsSeq) < (System.Math.Pow(2, 23)))) ||
                    (lastObsSeq > newObsSeq && ((lastObsSeq - newObsSeq) > (System.Math.Pow(2, 23)))) ||
                    DateTime.Now > lastObsRx.AddSeconds(128))
                {
                    //The value received from server is new....read the new temperature
                    //We got the temperature..it will be in payload in JSON
                    string payload = AbstractByteUtils.ByteToStringUTF8(coapReq.Payload.Value);
                    Hashtable keyVal = JSONResult.FromJSON(payload);
                     //int temp = Convert.ToInt32(keyVal["temp"].ToString());
                     //float temp = 10.1f;
 
                     float temp = (float)Double.Parse(keyVal["temp"].ToString());
                    Debug.Print("Temperature of Room is " + temp);
                   
 
Thanks 
escallanio







Also tagged with one or more of these keywords: Visual Studio, NetDuino Plus 2, Temperature Sensor, File Writing

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.