Poll
Question: Could someone help me get started with my code to read RSSI value?
Could someone help me get started with my code to read RSSI value? - 2 (66.7%)
Could someone help me get started with my code to read RSSI value? - 1 (33.3%)
Total Voters: 3

Pages: [1]   Go Down
Author Topic: Wifly arduino shield RSSI Vout (signal strength)  (Read 2864 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I have bought a Wifly shield for Arduino (http://www.sparkfun.com/products/9954). I want to read the strength of any Wifi signal in the area to control some LEDs, I noticed that the module incorporates a function called "show RSSI" as it says in the data sheet: http://www.sparkfun.com/datasheets/Wireless/WiFi/WiFlyGSX-um2.pdf.

I can't figure out how to successfully read a value for RSSI (signal strength). Would somebody be able to help me get started with this code?

Most recent library for Wifly: http://forum.sparkfun.com/viewtopic.php?f=32&t=25216.

This library includes three example codes.


Please help!!

Thanks, Darren.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8860
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have a serial port connected to the WiFly UART port?

You switch to command mode by sending "$$$".  I think you have to send nothing else within one seconds before and one second after.
Code:
delay(1000);
WiFly.write("$$$");
delay(1000);
If the first thing you get back is not "CMD" then something is wrong.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I voted for the second option, although I'm still not sure if I was right.

Hope that helps.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I voted for the first option, just to be contrary.

Hope that helps.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8860
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was going to vote for the underdog but they are tied at 1 and 1 so I'm going to boycott this poll instead.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for that.

Using: WiFly.write("$$$"); came up with an error: 'class WiFlyDevice' has no member named write. I replaced it with Serial.write("$$$");.

It returns: <2.23>

My code is attached to this post.


Darren

* WiFly_trying_to_read_rssi.pde (0.63 KB - downloaded 17 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually the code wasn't attached. Here it is:


#include "WiFly.h"
#include "Credentials.h"


void setup()
{
  Serial.begin(9600);      //initialise serial comms

  WiFly.begin();          //initialise WiFly comms

  delay(1000);
  Serial.write("$$$");        //initialise command mode
  delay(1000);
}


void loop(){

  delay(100);

  Serial.write("show rssi");      //request RSSI value

    while(SpiSerial.available()) {
    Serial.print(SpiSerial.read(), BYTE);

    /* if (WiFly.join(ssid, passphrase)) {
     int ch = WiFly.read();
     Serial.println(ch);
     
     }
     */
    if(Serial.available()) { // Outgoing data
      SpiSerial.println(Serial.read(), BYTE);
    }
  }
}

* WiFly_trying_to_read_rssi.pde (0.63 KB - downloaded 15 times.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.write("show rssi");      //request RSSI value
Serial.write() is for binary data. Serial.print() is for strings and for converting numeric types to strings. Why are you using Serial.write() this way?

Quote
Using: WiFly.write("$$$"); came up with an error: 'class WiFlyDevice' has no member named write. I replaced it with Serial.write("$$$");.
What is connected to the Serial port?  Why didn't you try LCD.write()?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was using Serial.wite() because I saw someone using it in another post. I'm now using SpiSerial.print() and the comms works with that.

This is a page about troubleshooting using the WiFly shield:

http://forum.sparkfun.com/viewtopic.php?f=32&t=25129
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My code is able now to write a series of commands to the WiFly shield in the following order:
- $$$ (with no carrige return)(this command enters command mode)
- set wlan ssid BTHub3-Q9Z8
- set wlan phrase df2387da92
- join BTHub3-Q9Z8
- show rssi

It seams to bring back a number for the signal strength (RSSI) but it isn't very consistent and its very slow to respond when I move the shield relative to my wifi router. My code:


#include "WiFly.h" // We use this for the preinstantiated SpiSerial object.
//#include "WiFlySerial.h"


int pos = 0;
int crap = 0;
int rssi_read = 0;
int rssi_val = 0;
long i = 0;


void setup() {

  Serial.begin(9600);
  Serial.println("SPI UART on WiFly Shield terminal tool");
  Serial.println("--------------------------------------"); 
  Serial.println();
  Serial.println("This is a tool to help you troubleshoot problems with the WiFly shield.");
  Serial.println("For consistent results unplug & replug power to your Arduino and WiFly shield.");
  Serial.println("(Ensure the serial monitor is not open when you remove power.)"); 
  Serial.println();

  Serial.println("Attempting to connect to SPI UART...");
  SpiSerial.begin();
  Serial.println("Connected to SPI UART.");
  Serial.println();

  Serial.println(" * Use $$$ (with no line ending) to enter WiFly command mode. (\"CMD\")");
  Serial.println(" * Then send each command followed by a carriage return.");
  Serial.println();

  Serial.println("Waiting for input.");
  Serial.println();
}


void loop(){
  Serial.println("loop");

 

//void command(){
  delay (1000);
  SpiSerial.print("$$$");      //enters WiFly's command mode, should return CMD
  delay (1000);
  Serial.print(SpiSerial.read(), BYTE);
 
 
  SpiSerial.println("set wlan ssid BTHub3-Q9Z8");
  //delay (2000);
  Serial.print(SpiSerial.read(), BYTE);
 
  SpiSerial.println("set wlan phrase df2387da92");
  //delay (200);
  Serial.print(SpiSerial.read(), BYTE);
 

  SpiSerial.println("join BTHub3-Q9Z8");
  delay(2000);
  Serial.print(SpiSerial.read(), BYTE);
  delay(2000);
  Serial.print(SpiSerial.read(), BYTE);
  delay(2000);


  SpiSerial.println("show rssi");
  Serial.print(SpiSerial.read(), BYTE);
 

  for(;smiley-wink{
  SpiSerial.println("show rssi");
  Serial.print(SpiSerial.read(), BYTE);   
  }
 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I based my code on the sample code:  SpiUartTerminal.pde

This code gives me a good predictable RSSI reading that dynamically updates when I move the shield relative to my router.

This code can be found here: http://forum.sparkfun.com/viewtopic.php?f=32&t=25129

And here:



/*

  SpiUartTerminal - tool to help troubleshoot problems with WiFly shield

  This code will initialize and test the SC16IS750 UART-SPI bridge then enable you
  to send commands to the WiFly module.

  Copyright (c) 2010 SparkFun Electronics. http://sparkfun.com LGPL 3.0

 */

#include "WiFly.h" // We use this for the preinstantiated SpiSerial object.


void setup() {

  Serial.begin(9600);
  Serial.println("SPI UART on WiFly Shield terminal tool");
  Serial.println("--------------------------------------"); 
  Serial.println();
  Serial.println("This is a tool to help you troubleshoot problems with the WiFly shield.");
  Serial.println("For consistent results unplug & replug power to your Arduino and WiFly shield.");
  Serial.println("(Ensure the serial monitor is not open when you remove power.)"); 
  Serial.println();
 
  Serial.println("Attempting to connect to SPI UART...");
  SpiSerial.begin();
  Serial.println("Connected to SPI UART.");
  Serial.println();
 
  Serial.println(" * Use $$$ (with no line ending) to enter WiFly command mode. (\"CMD\")");
  Serial.println(" * Then send each command followed by a carriage return.");
  Serial.println();
 
  Serial.println("Waiting for input.");
  Serial.println();   
 
}


void loop() {
  // Terminal routine

  // Always display a response uninterrupted by typing
  // but note that this makes the terminal unresponsive
  // while a response is being received.
  while(SpiSerial.available() > 0) {
    Serial.print(SpiSerial.read(), BYTE);
  }
 
  if(Serial.available()) { // Outgoing data
    SpiSerial.print(Serial.read(), BYTE);
  }
}
Logged

Pages: [1]   Go Up
Jump to: