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

Netduino RF Receiver


  • Please log in to reply
4 replies to this topic

#1 Dino Novak

Dino Novak

    New Member

  • Members
  • Pip
  • 5 posts

Posted 18 August 2012 - 03:44 PM

HI,

I hooked up RF 433 receiver to NetDuino in order to receive RF transmissions from Oregon Scientific THGN122 sensor.
RF Receiver: http://www.hwkitchen...hz-rf-link-kit/

I simply set data out of receiver to RX pin for COM2:

// initialize the serial port for COM2 (using D2 & D3)
rf433 = new SerialPort(SerialPorts.COM2, 115200, Parity.None, 8, StopBits.One);
// open the serial-port, so we can send & receive data
rf433.Open();
// add an event-handler for handling incoming data
rf433.DataReceived += new SerialDataReceivedEventHandler(rf433_DataReceived);

In the datareceived handler I am buffering incoming data till size is 1024 btes and then dumping it to SD card as text file (converted to hex)

static void rf433_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int count = 1024;
            byte[] ComBuffer = new byte[count];
            int readBytes = 0;
            int totalReadBytes = 0;
            int offset = 0;
            int remaining = 1024;
            string RFLogPath = @"\SD\rflogout.txt";

            //buffer received
            try
            {
                do
                {
                    readBytes = rf433.Read(ComBuffer, offset, remaining);
                    offset = offset + readBytes;
                    remaining = remaining - readBytes;
                    totalReadBytes = totalReadBytes + readBytes;
                } while (remaining > 0 && readBytes > 0);
            }
            catch (System.Exception ex)
            {
                byte[] temp = new byte[totalReadBytes - 1];
                if (ComBuffer != null)
                    Array.Copy(ComBuffer, temp, System.Math.Min(ComBuffer.Length, temp.Length));
                ComBuffer = temp;
            }
            
            //save to file
            using (StreamWriter writer = new StreamWriter(RFLogPath, true))
                    {
                        writer.WriteLine(DateTime.Now.ToString() + ":");        
                        for (int i = 0; i < ComBuffer.Length; i++)
                        {
                            writer.Write(ByteToHex(ComBuffer[i]) + "-");
                        }
                        writer.Flush();
                    }
                    
             
        }

This is producing file as attached but I am unable to decipher any repeating transmissions.
I set up port speed to 115200 to avoid loosing some data but it looks like 1024 buffer fills up in cca 6 - 7 seconds.
Also I see a lot of traffic so I suspect that there is a number of devices around since bytes keep coming up even if I disconnect my sensor.

Anyone can help with deciphering or recognizing byte pattern of Oregon sensor ?

Thanx,
DiNo

Attached Files



#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 18 August 2012 - 05:10 PM

Hello Dino. First off, there's no attached file, but it seems a secondary problem. Secondly, it seems to me that you mixed the event-reception with a loop-data collection. Either you use the event, or a loop for collecting the incoming data. The loop-way is simpler and more intuitive, but requires the loop running in a dedicate thread, otherwise the main program locks. The event-way does the loop for you (hidden), but you should manage the incoming events, then collect the data in a dedicate session. Here is a link to another post, related to a simple data exchange with a GSM modem (i.e. a cell-phone). It does even more than you actually need, because it allows the Netduino to send data to the modem, but you don't need it. Just have a look at the program, and cut off any sending (write) command, then use only the receiving sections. http://forums.netdui...dpost__p__21225 Hope it helps. Cheers PS: when you have to insert piece of code in this forum, just take care to wrap it with the "Insert code snippet" button, above in the post-toolbar. It will format the code properly, because otherwise it's pretty hard to read.
Biggest fault of Netduino? It runs by electricity.

#3 Dino Novak

Dino Novak

    New Member

  • Members
  • Pip
  • 5 posts

Posted 18 August 2012 - 06:00 PM

HI, thanx for feedback. I just edited the post and attached the file and tidy - up the code part. At the moment code optimization and second thread as data gathering is not a priority. I just want to see what the receiver is getting in order to recognize the interesting traffic. what suprizes me is the amount of data that is flowing around at 433 Mhz. So it is rather hard to recognize interesting traffic Regards, DiNo

#4 Dugley DoRight

Dugley DoRight

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationSeattle, Washington

Posted 19 August 2012 - 03:49 PM

Dino,

Checkout this link Wireless Temperature Sensor : La Crosse

#5 theaccent

theaccent

    Member

  • Members
  • PipPip
  • 12 posts

Posted 09 June 2015 - 11:59 AM

Hi, did you ever get this to work and could you post the zip of your code?






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.