Forum >can i use mutiple features like get GPS SEND SMS and send http request at the time on the sim 808

can i use mutiple features like get GPS SEND SMS and send http request at the time on the sim 808

userHead Elijah.Kawinga 2025-02-13 04:00:24 628 Views2 Replies

it wont allow me to send messages after the request
 

#include <DFRobot_SIM808.h>


 

DFRobot_SIM808 sim808(&Serial);

float lat = 0.0;

float lon = 0.0;

 

char buffer[512];

char http_cmd[256];


 

#define PHONE_NUMBER "0884348727"


 

void setup() {

  //mySerial.begin(9600);

  Serial.begin(9600);


 

  //******** Initialize sim808 module *************

  while (!sim808.init()) {

    delay(1000);

    Serial.print("Sim808 init error\r\n");

  }


 

 



 

  //************* Turn on the GPS power************

  // sim808_send_cmd()

  if (sim808.attachGPS())

    Serial.println("Open the GPS power success");

  else

    Serial.println("Open the GPS power failure");

}


 

void loop() {

  //************** Get GPS data *******************


 

  // Serial.println("attempting to get data ");

  if (sim808.getGPS()) {

    Serial.print(sim808.GPSdata.year);

    Serial.print("/");

    Serial.print(sim808.GPSdata.month);

    Serial.print("/");

    Serial.print(sim808.GPSdata.day);

    Serial.print(" ");

    Serial.print(sim808.GPSdata.hour);

    Serial.print(":");

    Serial.print(sim808.GPSdata.minute);

    Serial.print(":");

    Serial.print(sim808.GPSdata.second);

    Serial.print(":");

    Serial.println(sim808.GPSdata.centisecond);

    Serial.print("latitude :");

    Serial.println(sim808.GPSdata.lat,6);

    Serial.print("longitude :");

    Serial.println(sim808.GPSdata.lon, 6);

   

    Serial.print("speed_kph :");

    Serial.println(sim808.GPSdata.speed_kph);

    Serial.print("heading :");

    Serial.println(sim808.GPSdata.heading);

    Serial.println();

    lon = sim808.GPSdata.lon, 6;

    lat = -sim808.GPSdata.lat, 6;


 

    //************* Turn off the GPS power ************

    sim808.detachGPS();

    delay(2000);

    sendR();

    delay(2000);

    sendGoogleMapsLink("0884348727");

   

  }

}



 

void sendR(){


 

  while(!sim808.join(F("internet"))) {

        Serial.println("Sim808 join network error");

        delay(2000);

    }

    // char http_cmd ="hello";

  // String data = "GET /dumi/send.php?device_id=5555&lat="+ String(lat, 6)+"&lon="+String(lat, 6)+" HTTP/1.1\r\nHost: www.bluecoregames.com\r\n\r\n";

  // char http_cmd[] = http_cmd.c_str();

  snprintf(http_cmd, sizeof(http_cmd),

         "GET /dumi/send.php?device_id=5555&lat=%.6f&lon=%.6f HTTP/1.1\r\nHost: www.bluecoregames.com\r\n\r\n",

         lat, lon);


 

  // const char* http_cmd = http_cmd.c_str();

   //************ Successful DHCP ****************

    Serial.print("IP Address is ");

    Serial.println(sim808.getIPAddress());


 

    //*********** Establish a TCP connection ************

    if(!sim808.connect(TCP,"www.bluecoregames.com", 80)) {

        Serial.println("Connect error");

    }else{

        Serial.println("Connect bluecore success");

    }


 

    //*********** Send a GET request *****************

    Serial.println("waiting to fetch...");

    sim808.send(http_cmd, sizeof(http_cmd)-1);

    while (true) {

        int ret = sim808.recv(buffer, sizeof(buffer)-1);

        if (ret <= 0){

            Serial.println("fetch over...");

            break;

        }

        buffer[ret] = '\0';

        Serial.print("Recv: ");

        Serial.print(ret);

        Serial.print(" bytes: ");

        Serial.println(buffer);

        break;

    }


 

    //************* Close TCP or UDP connections **********

    sim808.close();


 

    //*** Disconnect wireless connection, Close Moving Scene *******

    sim808.disconnect();

}




 

void sendGoogleMapsLink(const char *recipient) {

  if (lat != 0.0 && lon != 0.0) {

    String googleMapsLink = "https://www.google.com/maps?q=" + String(lat, 6) + "," + String(lon, 6);

    if (sim808.sendSMS(recipient, googleMapsLink.c_str())) {

      Serial.println("Sent SMS with Google Maps link: " + googleMapsLink);

    } else {

      Serial.println("Failed to send SMS.");

    }

  } else {

    Serial.println("GPS data unavailable, cannot send link.");

  }

}

2025-02-18 14:09:44

Can you show me your error message?

userHeadPic sun.haihui
Elijah.Kawinga wrote:

it does not show any error i used Serial.println("Failed to send SMS.")

as a way to check if it send the sms

 

2025-02-24 16:25:52
1 Replies