I have the following code that can read a web page using HTTP get but I can only do it because the website I am doing it to has a static IP address, but in my project I am just hosting it on a free service and IP changes rapidly. So is there a way to do the same with only the URL address?

#include <SoftwareSerial.h>

SoftwareSerial cell(2,3);  // Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin. connect this to the GSM module

const String apn = "web2"; // access-point name for GPRS

const String ip = ""; // IP address of server we're connecting to
const String host = "kfu.edu.sa"; // required in HTTP 1.1 - what's the name of the host at this IP address?
const String request = "GET /sites/Home HTTP/1.1";
const String useragent = "Mozilla/5.0"; // for our purposes the user agent doesn't matter - if I understand correctly it's helpful to use something generic the server will recognize

void setup()
  //Initialize serial ports for communication with computer

  Serial.println("Starting SM5100B Communication...");

  waitTil("+SIND: 4"); // keep printing cell output til we get "+SIND: 4"
  Serial.println("Module ready");

void loop()
  Serial.println("Attaching GPRS...");

  Serial.println("Setting up PDP Context...");

  Serial.println("Activating PDP Context...");

  Serial.println("Configuring TCP connection to TCP Server...");

  Serial.println("Starting TCP Connection...");

  delay(5000); // wait for the socket to connect
  • have you tried using a URL in place of IP? ....... ip="google.com"; cell.println("AT+SDATACONF=1,\"TCP\",\""+ip+"\",80"); – jsotola Mar 1 at 0:51
  • Yes, but it does not give "OK" back. – Salman Sayah Mar 1 at 0:52
  • you get absolutely nothing back? – jsotola Mar 1 at 0:54
  • the method getMessage() gives "⸮⸮⸮⸮⸮" – Salman Sayah Mar 1 at 1:06
  • what are the bytes in the returned string? – jsotola Mar 1 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.