Hello there, I'm using Arduino uno with sim808 and my goal is to use arduino as a server to get requests from my api or (preferable if it's possible) make the Arduino listen to a specific server and fetch any received requests.
I searched all over the inernet and tried every code related but nothing seems to work.
i tried the following code(taken from another user in this forum) and it's not giving me any errors but I dont know how to test if Arduino can get requests.
#include <inetGSM.h>
#include <SoftwareSerial.h>
#include <SIM900.h>
#include <LOG.h>
InetGSM inet;
char msg[50];
char ip[20];
int numdata;
char inSerial[50];
int i = 0;
boolean started = false;
long lasttime = millis();
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower
if (gsm.begin(4800)) {
Serial.println("\nstatus=READY");
started = true;
}
else Serial.println("\nstatus=IDLE");
if (started) {
//GPRS attach, put in order APN, username and password.
//If no needed auth let them blank.
if (inet.attachGPRS((char *)"CMNET", (char *)"", (char *)""))
Serial.println("status=ATTACHED");
else Serial.println("status=ERROR");
delay(1000);
//Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
delay(5000);
int i = 0;
while (i < 20) {
gsm.SimpleRead();
i++;
}
Serial.println(msg);
delay(5000);
if (inet.connectTCPServer(80))
Serial.println("status=TCPSERVERWAIT");
else Serial.println("ERROR in Server");
lasttime = millis();
}
};
void loop()
{
if (started) {
//Check if there is an active connection.
if (inet.connectedClient()) {
Serial.println("client connected");
//Read and print the last message received.
gsm.read(msg, 50);
Serial.println(msg);
Serial.println("msg read");
}
}
else {
Serial.println("client not connected");
serialhwread();
serialswread();
}
};
void serialhwread()
{
i = 0;
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i] = (Serial.read());
delay(10);
i++;
}
inSerial[i] = '\0';
if (!strcmp(inSerial, "/END")) {
Serial.println("_");
inSerial[0] = 0x1a;
inSerial[1] = '\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if (!strcmp(inSerial, "TEST")) {
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
}
//Read last message saved.
if (!strcmp(inSerial, "MSG")) {
Serial.println(msg);
}
else {
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0] = '\0';
}
}
void serialswread()
{
gsm.SimpleRead();
}
another code I tried is this
/*
GSM Web Server
A simple web server that shows the value of the analog input pins.
using a GSM shield.
Circuit:
* GSM shield attached
* Analog inputs attached to pins A0 through A5 (optional)
created 8 Mar 2012
by Tom Igoe
*/
// libraries
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// APN data
#define GPRS_APN "CMNET" // replace your GPRS APN
#define GPRS_LOGIN "" // replace with your GPRS login
#define GPRS_PASSWORD "" // replace with your GPRS password
// initialize the library instance
GPRS gprs;
GSM gsmAccess(true); // include a 'true' parameter for debug enabled
GSMServer server(80); // port 80 (http default)
// timeout
const unsigned long __TIMEOUT__ = 10 * 1000;
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("Connected to GPRS network");
// start server
server.begin();
//Get IP.
IPAddress LocalIP = gprs.getIPAddress();
Serial.println("Server IP address=");
Serial.println(LocalIP);
}
void loop() {
// listen for incoming clients
GSMClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
Serial.println("Receiving request!");
bool sendResponse = false;
while (char c = client.read()) {
if (c == '\n') {
sendResponse = true;
}
}
// if you've gotten to the end of the line (received a newline
// character)
if (sendResponse) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
client.println("</html>");
//necessary delay
delay(1000);
client.stop();
}
}
}
}
}
but it gives me error at this command: AT+QIFGCNT=0
I appreciate any help