posting information on serial monitor to a website/ webserver

Hello guys i have been able to send sensor data to a website with no problems. the problem am having now is that:

i am using a gsm sim900 and arduino together, whenever i call my number on the gsm i get a ring and the caller id displayed on the serial monitor of the arduino. what i want to do is send this displayed message to a website (then server later).

i have the code to post tem and hum sensor to a website working but cant get it to work with the gsm module.

thanks any suggestions are appreciated

Take the part of your GSM sketch that displays the Caller ID on Serial and store the Caller ID in a variable. Take the part of the sketch that posts temperature and humidity and add a similar part that posts the Caller ID. I could be more specific but I can't see any of your sketches from here.

Thanks for replying.

my code for the gsm module
#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8);
//String a;call
char a;
int b=0;

void setup() {

mySerial.begin(19200); // opens serial port, sets data rate to 9600 bps
Serial.begin(19200); // Setting the baud rate of Serial Monitor (Arduino)
Serial.println("GSM SIM900A BEGIN");
}

void loop() {
if (mySerial.available()) {
a= mySerial.read();
Serial.print(a);

if (a=='R'){

b++;
Serial.print("RING COUNT = ");
// Serial.print(" || ");
// Serial.println(a);
Serial.print(b);

}
if(b==4)
{
mySerial.println("ATH");
Serial.println("RING HANG");// Hang up at command
delay(100);

b=0;
}

if(a=='+'){
Serial.println(" Caller_id: ");
}

}
}

the problem with the gsm module is i only get the ring on the serial monitor when i call my number on it.
i cant find a way to save the output into a variable
the out put is this

RRING COUNT =
1
ING

+Caller_id: CLIP: "+Caller_id: 971557292422",145,"",,"",0

RRING COUNT =
2
ING

+Caller_id: CLIP: "+Caller_id: 971557292422",145,"",,"",0

RRING COUNT =
3
ING

+Caller_id: CLIP: "+Caller_id: 971557292422",145,"",,"",0

RRING COUNT =
4
RING HANG
ING
ATH

OK

if theres any way to save this into a variable then i can replace it with the tem and hum data and send it to the website.

code to post to website

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Enter the IP address for Arduino, as mentioned we will use 192.168.0.16
// Be careful to use , insetead of . when you enter the address here
IPAddress ip(192,168,1,154);

int photocellPin = 0; // Analog input pin on Arduino we connected the SIG pin from sensor
int photocellReading; // Here we will place our reading

// Initialize the Ethernet server library
EthernetServer server(80);

void setup() {

// Serial.begin starts the serial connection between computer and Arduino
Serial.begin(9600);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("Arduino server IP address: ");
Serial.println(Ethernet.localIP());
}

void loop() {

photocellReading = analogRead(photocellPin); // Fill the sensorReading with the information from sensor

EthernetClient client = server.available(); // Listen for incoming clients

if (client) {

// When a client sends a request to a webserver, that request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();

// This line is used to send communication information between Arduino and your browser over Serial Monitor
Serial.write(c);

// When the request has ended send the client a reply
if (c == '\n' && currentLineIsBlank) {

// We send the HTTP response code to the client so it knows that we will send him HTML data
// and to refresh the webpage every 5 seconds
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5");
client.println();
// Here we write HTML data (for the page itself) which will be sent to the client.
// The HTML includes Javascript which fills the data
client.println("");
client.println("");
client.println("");
client.println("Arduino sensor data");
client.println("");
client.println("");
client.println("");
client.println("
");
client.println("

Light measured from the sensor is:

");
client.println("

");
client.println("");
client.println("");
break;
}
if (c == '\n') {
// Check if a new line is started
currentLineIsBlank = true;
}
else if (c != '\r') {
// If a new line was not strated
currentLineIsBlank = false;
}
}
}
// Give the client some time to recieve the data (1ms)
delay(100);
// In the end close the connection
client.stop();
}
}

The first part of the problem is reading the Caller ID. Right now you are looking for single characters: 'R' or '+'. When the GSM module sends 'RING' you see 'R' and output "RING COUNT=" and the ring count on a separate line. That is why the output says:

RRING COUNT = 
1
ING

It will make life easier if you read the input as it arrives and only process the input when an 'end of line' character ('\r' or '\n') arrives. Try this to see how the output looks:

#include <SoftwareSerial.h>


SoftwareSerial mySerial(7, 8);


const byte BufferSize = 80;
char Buffer[BufferSize];
byte BufferIndex = 0;


int b = 0;


void setup()
{
  mySerial.begin(19200); // opens serial port, sets data rate to 9600 bps
  Serial.begin(19200);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println("GSM SIM900A BEGIN");
}


void loop()
{
  if (mySerial.available())
  {
    char c = mySerial.read();


    if (c == '\r' || c == '\n')
    {
      ProcessBuffer();
      BufferIndex = 0;
    }
    else
    {
      // Add the character to the buffer
      if (BufferIndex < BufferSize - 1) // Leave room for terminator
        Buffer[BufferIndex++] =  c;
      Buffer[BufferIndex] = '\0';  // Null terminator
    }
  }
}


void ProcessBuffer()
{
  // If the buffer is empty, we're done
  if (BufferIndex == 0)
    return;


  // Recognize the RING message
  if (strcmp(Buffer, "RING") == 0)
  {
    b++;
    Serial.print("RING COUNT = ");
    Serial.println(b);


    // On the forth "RING"
    if (b == 4)
    {
      mySerial.println("ATH");
      Serial.println("RING HANG");// Hang up at command
      b = 0;
    }
    return;  // RING handled
  }


  // Recognize the message +CLIP: "+971557292422",145,"",,"",0
  if (strncmp(Buffer, "+CLIP:", 6) == 0)
  {
    Serial.print("Caller_id: ");
    Serial.println(Buffer + 6);  // The contents of the CLIP message
    return;
  }


  // If the line isn't recognized:
  Serial.print("UNRECOGNIZED: \"");
  Serial.print(Buffer);  // The contents of the buffer
  Serial.println("\"");
}

Thanks for the code i got this output:

RING COUNT = 1
Caller_id: "045541535",161,"",,"",0
RING COUNT = 2
Caller_id: "045541535",161,"",,"",0
RING COUNT = 3
Caller_id: "045541535",161,"",,"",0
RING COUNT = 4
RING HANG
Caller_id: "045541535",161,"",,"",0
UNRECOGNIZED: "ATH"
UNRECOGNIZED: "OK"

is there anyway i can send this output to the website as soon as it is displayed on the serial monitor

Reading the code johnwasser posted, that seems trivial. In that code, the data is stored in a char array (called Buffer), and then printed to the Serial monitor. That's great for testing as you know what's actually in the Buffer.

Now instead of printing it to the Serial monitor, you transmit it to your web site. Or, for testing, after printing it to the Serial monitor, you transmit it to your web site.

Now we know that the message contains +CLIP:"the number",data,... We just need to copy digits starting at index 7.

  // Recognize the message +CLIP: "+971557292422",145,"",,"",0
  if (strncmp(Buffer, "+CLIP:", 6) == 0)
  {
    for (int i=7; isdigit(Buffer[i]); i++)
    {
      CallingNumber[i-7] = Buffer[i];
      CallingNumber[i-6] = '\0';  // Null Terminator
    }
    
    Serial.print("Caller_id: ");
    Serial.println(CallingNumber);  // The contents of the CLIP message
    return;
  }

Thanks every one i got it to work fine now :slight_smile:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8);

const byte BufferSize = 80;
char Buffer[BufferSize];
byte BufferIndex = 0;
String Call_info;
String no_ring;

int b = 0;

void setup()
{
mySerial.begin(19200); // opens serial port, sets data rate to 9600 bps
Serial.begin(19200); // Setting the baud rate of Serial Monitor (Arduino)
Serial.println("GSM SIM900A BEGIN");
}

void loop()
{
if (mySerial.available())
{
char c = mySerial.read();

if (c == '\r' || c == '\n')
{
ProcessBuffer();
BufferIndex = 0;
}
else
{

// Add the character to the buffer
if (BufferIndex < BufferSize - 1) // Leave room for terminator
Buffer[BufferIndex++] = c;
Buffer[BufferIndex] = '\0'; // Null terminator
}

}

}

void ProcessBuffer()
{
// If the buffer is empty, we're done

if (BufferIndex == 0)
return;

// Recognize the RING message
if (strcmp(Buffer, "RING") == 0)
{
b++;
no_ring =(b);
Serial.print("RING COUNT = ");
Serial.println(b);

// On the forth "RING"
// if (b == 4)
// {
// mySerial.println("ATH");
// Serial.println("RING HANG");// Hang up at command
// b = 0;
// }
return; // RING handled
}

// Recognize the message +CLIP: "+971557292422",145,"",,"",0
if (strncmp(Buffer, "+CLIP:", 6) == 0)
{
Call_info = (Buffer + 6);
Serial.print("Caller_id: ");
Serial.println(Buffer + 6); // The contents of the CLIP message
return;
}

// If the line isn't recognized:
Serial.print("UNRECOGNIZED: "");
Serial.print(Buffer); // The contents of the buffer
Serial.println(""");
if (strncmp(Buffer, "NO CARRIER", 9)==0){
Serial.print("call end");
Serial.println(no_ring);
Serial.println(Call_info);
}
}