Tutorial.GSMToolsGsmScanNetworks History

Hide minor edits - Show changes to markup

March 11, 2013, at 10:27 AM by Scott Fitzgerald -
Changed lines 214-219 from:
to:
February 04, 2013, at 09:33 AM by Scott Fitzgerald -
Changed lines 5-6 from:

This example prints out the IMEI number of the modem, then checks to see if it's connected to a carrier. If so, it prints the phone number associated with the SIM card. Then it scans for nearby networks and prints out their signal strengths.

to:

This example prints out the IMEI number of the modem, then checks to see if it's connected to a carrier and prints out its signal strength. It also scans for all nearby networks.

February 04, 2013, at 09:30 AM by Scott Fitzgerald -
Changed lines 5-6 from:

This sketch gives you diagnostic information about the network the GSM shield is connected to.

to:

This example prints out the IMEI number of the modem, then checks to see if it's connected to a carrier. If so, it prints the phone number associated with the SIM card. Then it scans for nearby networks and prints out their signal strengths.

Changed line 11 from:
  • SIM card with a data connection
to:
  • SIM card
Changed lines 31-32 from:

Define a number of constants that contain information about the GPRS network you're going to connect to. You'll need the Access Point Name (APN), login, and password. To obtain this information, contact your network provider for the most up to date information. This page has some information about various carrier settings, but it may not be current.

to:

Initialize instances of the classes you're going to use. You're going to need the GSM, GSMScanner, and GSMModem classes.

Changed lines 34-36 from:
  1. define GPRS_APN "GPRS_APN"
  2. define GPRS_LOGIN "login"
  3. define GPRS_PASSWORD "password"
to:

GSM gsmAccess; GSMScanner scannerNetworks; GSMModem modemTest;

Changed lines 39-40 from:

Initialize instances of the classes you're going to use. You're going to need the GSM, GPRS, GSMServer, and GSMClient classes. When you instantiate the GSMServer class, you'll need to tell it which port to listen for incoming connections. Port 80 is the default port for HTTP requests.

to:

Create a variable to hold the IMEI number, and a status messages to send to the serial monitor:

Changed lines 42-45 from:

GSMClient client; GPRS gprs; GSM gsmAccess; GSMServer server(80);

to:

String IMEI = "";

String errortext = "ERROR";

Changed lines 47-48 from:

Create some variables to set a timeout period, flag incoming client messages, and a buffer to read incoming bytes. to hold the server, path, and port you wish to connect to.

to:

In setup, open a serial connection to the computer. After opening the connection, send a message to the Serial Monitor indicating the sketch has started. Call @scannerNetworks.begin()@@ to reset the modem.

Changed lines 51-53 from:

char server[] = "arduino.cc"; char path[] = "/"; int port = 80;

to:

void setup(){

  Serial.begin(9600); 
  Serial.println("GSM networks scanner");
  scannerNetworks.begin();
Changed lines 57-58 from:

In setup, open a serial connection to the computer. After opening the connection, send a message indicating the sketch has started.

to:

Create a local variable to track the connection status. You'll use this to keep the sketch from starting until the SIM is connected to the network :

Changed lines 60-62 from:

void setup(){

  Serial.begin(9600); 
  Serial.println("Starting Arduino web client.");
to:
  boolean notConnected = true;
Changed lines 63-64 from:

Create a local variable to track the connection status. You'll use this to keep the sketch from starting until the SIM is connected to the network :

to:

Connect to the network by calling gsmAccess.begin(). It takes the SIM card's PIN as an argument. By placing this inside a while() loop, you can continually check the status of the connection. When the modem does connect, gsmAccess() will return GSM_READY. Use this as a flag to set the notConnected variable to true or false. Once connected, the remainder of setup will run.

Deleted lines 65-72:
Deleted line 68:
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
Changed lines 78-79 from:

Attempt to connect to the server using client.connect(). connect() requires two arguments, the server and port. Once connected to the server, make a HTTP request by calling client.print(). A typical web request looks like "GET pathname HTTP/1.0". print will send the message, just as a browser would.

to:

Get the IMEI of the modem with modemTest.getIMEI() and print it out to the serial monitor.

Changed lines 81-88 from:
  if (client.connect(server, port))
  {
    Serial.println("connected");
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.0");
    client.println();
  } 
to:
  Serial.print("Modem IMEI: ");
  IMEI = modemTest.getIMEI();
  IMEI.replace("\n","");
  if(IMEI != NULL)
    Serial.println(IMEI);
Changed lines 88-89 from:

If the connection to the server failed, make a note of it in the serial monitor, and close up setup.

to:

In loop(), scan and print out all available networks. This may take some time

Changed lines 92-96 from:
  else
  {
    Serial.println("connection failed");
  }

}

to:
  Serial.println("Scanning available networks. May take some seconds.");
  Serial.println(scannerNetworks.readNetworks());
Changed lines 96-97 from:

Inside loop, check to see if there are bytes returned from the server. If so, read them and print them to the serial monitor.

to:

Print out the current connected carrier, and the strength of the signal. Signal strength is on a scale of 0-31, where 0 is the lowest, and 31 is the highest. close the loop().

Changed lines 99-103 from:
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }
to:
  Serial.print("Current carrier: ");
  Serial.println(scannerNetworks.getCurrentCarrier());

  Serial.print("Signal Strength: ");
  Serial.print(scannerNetworks.getSignalStrength());
  Serial.println(" [0-31]");
Changed lines 107-108 from:

If the server disconnects, which it will typically do once it has completed the HTTP request, stop the client locally and close the loop.

to:
Changed lines 111-125 from:
to:

/*

Changed lines 113-116 from:
to:
 GSM Scan Networks
Changed lines 115-120 from:
 This sketch connects an analog sensor to Pachube (http://www.pachube.com)
 using a Telefonica GSM/GPRS shield.

 This example has been updated to use version 2.0 of the Pachube.com API. 
 To make it work, create a feed with a datastream, and give it the ID
 sensor1. Or change the code below to match your feed.
to:
 This example prints out the IMEI number of the SIM card,
 then check to see if it's connected to a carrier. If so, 
 it prints the phone number associated with the card.
 Then it scans for nearby networks and prints out their signal strengths.
Changed lines 121-122 from:
 * Analog sensor attached to analog in 0
 * GSM shield attached to pins 10, 11, 12, 13
to:
 * GSM shield attached
Changed lines 123-128 from:
 created 4 March 2012
 by Tom Igoe
 and adapted for GSM shield by David Del Peral

 This code is in the public domain.
to:
 Created 8 Mar 2012
 by Tom Igoe, implemented by Javier Carazo
 Modified 18 Jan 2013
 by Scott Fitzgerald
Deleted lines 131-135:

// Pachube Client data

  1. define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here
  2. define FEEDID 00000 // replace your feed ID
  3. define USERAGENT "My Project" // user agent is the project name
Changed lines 135-153 from:

// APN data

  1. define GPRS_APN "GPRS_APN" // replace your GPRS APN
  2. define GPRS_LOGIN "login" // replace with your GPRS login
  3. define GPRS_PASSWORD "password" // replace with your GPRS password

// initialize the library instance: GSMClient client; GPRS gprs; GSM gsmAccess; // include a 'true' parameter for debug enabled

// if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: //IPAddress server(216,52,233,121); // numeric IP for api.pachube.com char server[] = "api.pachube.com"; // name address for pachube API

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com

to:

// initialize the library instance GSM gsmAccess; // include a 'true' parameter to enable debugging GSMScanner scannerNetworks; GSMModem modemTest;

// Save data variables String IMEI = "";

// serial monitor result messages String errortext = "ERROR";

Added lines 150-151:
  Serial.println("GSM networks scanner");
  scannerNetworks.begin();
Changed lines 160-161 from:
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
to:
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
Added lines 168-186:
  // get modem parameters
  // IMEI, modem unique identifier
  Serial.print("Modem IMEI: ");
  IMEI = modemTest.getIMEI();
  IMEI.replace("\n","");
  if(IMEI != NULL)
    Serial.println(IMEI);

  // currently connected carrier
  Serial.print("Current carrier: ");
  Serial.println(scannerNetworks.getCurrentCarrier());

  // returns strength and ber
  // signal strength in 0-31 scale. 31 means power > 51dBm
  // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
  Serial.print("Signal Strength: ");
  Serial.print(scannerNetworks.getSignalStrength());
  Serial.println(" [0-31]");
Changed lines 190-208 from:

{

  // read the analog sensor:
  int sensorReading = analogRead(A0);   

  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available())
  {
     char c = client.read();
     Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected)
  {
    client.stop();
  }
to:

{

  // scan for existing networks, displays a list of networks
  Serial.println("Scanning available networks. May take some seconds.");
Changed lines 194-199 from:
  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && ((millis() - lastConnectionTime) > postingInterval))
  {
  sendData(sensorReading);
  }
to:
  Serial.println(scannerNetworks.readNetworks());
Changed lines 196-198 from:
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
to:
    // currently connected carrier
  Serial.print("Current carrier: ");
  Serial.println(scannerNetworks.getCurrentCarrier());

  // returns strength and ber
  // signal strength in 0-31 scale. 31 means power > 51dBm
  // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
  Serial.print("Signal Strength: ");
  Serial.print(scannerNetworks.getSignalStrength());
  Serial.println(" [0-31]");
Deleted lines 207-279:

/*

  This method makes a HTTP connection to the server.
  • /

void sendData(int thisData) {

  // if there's a successful connection:
  if (client.connect(server, 80))
  {
    Serial.println("connecting...");

    // send the HTTP PUT request:
    client.print("PUT /v2/feeds/");
    client.print(FEEDID);
    client.println(".csv HTTP/1.1");
    client.print("Host: api.pachube.com\n");
    client.print("X-ApiKey: ");
    client.println(APIKEY);
    client.print("User-Agent: ");
    client.println(USERAGENT);
    client.print("Content-Length: ");

    // calculate the length of the sensor reading in bytes:
    // 8 bytes for "sensor1," + number of digits of the data:
    int thisLength = 8 + getLength(thisData);
    client.println(thisLength);

    // last pieces of the HTTP PUT request:
    client.print("Content-Type: text/csv\n");
    client.println("Connection: close");
    client.println();

    // here's the actual content of the PUT request:
    client.print("sensor1,");
    client.println(thisData);
  } 
  else
  {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
  // note the time that the connection was made or attempted
  lastConnectionTime = millis();

}

/*

  This method calculates the number of digits in the
  sensor reading.  Since each digit of the ASCII decimal
  representation is a byte, the number of digits equals
  the number of bytes.
  • /

int getLength(int someValue) {

  // there's at least one byte:
  int digits = 1;

  // continually divide the value by ten, 
  // adding one to the digit count for each
  // time you divide, until you're at 0:
  int dividend = someValue /10;
  while (dividend > 0)
  {
    dividend = dividend /10;
    digits++;
  }

  // return the number of digits:
  return digits;

}

February 03, 2013, at 07:26 PM by Scott Fitzgerald -
Changed lines 1-6 from:

Examples > Make Voice Call

Using the GSM Shield to Make Calls

This example shows how to use the GSM Shield and Library to make voice calls. Please click here for more information on the GSM library.

to:

Examples > GSM library

GSM Scan Networks

This sketch gives you diagnostic information about the network the GSM shield is connected to.

Changed line 11 from:
  • SIM card
to:
  • SIM card with a data connection
Changed lines 23-25 from:

The code below is configured for use with a GSM/GPRS shield. In the variable declaration area, you need to instantiate both the GSM and GSMVoiceCall classes. Inside setup(), call GSM.begin(), with the PINNUMBER of your SIM card as parameter. GSM.begin() will return whether the shield managed to connect to the GSM network or not.

In the loop(), the input from the Serial Monitor is used to tell the GSM Shield a phone number to call to. The code waits until the call is over before performing any other actions.

to:
Changed lines 141-322 from:
to:
Changed line 328 from:
to:
November 16, 2012, at 07:58 PM by Scott Fitzgerald -
Added lines 1-34:

Share