first and second quotes are the same thing written differently(that's what i'm currently able to do with the ethernet shield and one of the goals of my project, the last quote is the actual information i need from this thread.
I'm not asking HOW to do it, what i'm asking if it's possible to do it similarly as the ethernet shield with the SIM800L shield.
this is my current code using the ethernet shield.
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
// this code generates data from the sensors and makes an http request to a local server and the page requested makes an insert of the data passed
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// Enter the IP address for Arduino
// Be careful to use , insetead of . when you enter the address here
IPAddress ip(192, 168, 0, 170);
int vcc = 5; //attach pin 2 to vcc
int trig = 6; // attach pin 3 to Trig
int echo = 7; //attach pin 4 to Echo
int gnd = 8; //attach pin 5 to GND
float cm1;
float cm2;
float cm3;
float cm4;
float cm5;
bool isparked1;
bool isparked2;
bool isparked3;
bool isparked4;
bool isparked5;
long duration;
long duration1;
long duration2;
long duration3;
long duration4;
long duration5;
char server[] = "192.168.0.11";//direccion o ip del servidor (en este caso estamos usando un servidor local por lo tanto usamos la ip de esta maquina
// Initialize the Ethernet server library
EthernetClient client;
void setup() {
pinMode (vcc, OUTPUT);
pinMode (gnd, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
}
//metodo para calcular los centimetros
float microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
//metodo para ejecutar la medicion
long ejecutarMedicion()
{
pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(5);
digitalWrite(trig, LOW);
pinMode(echo, INPUT);
duration = pulseIn(echo, HIGH);//photocell
return duration;
}
void loop() {
digitalWrite(vcc, HIGH);
Serial.println();
Serial.print("comenzando loop");
Serial.println();
Serial.print("haciendo nueva medicion 1");
Serial.println();
//medicion
duration1 = ejecutarMedicion();
//fin medicion
//calculo en centimetros
cm1 = microsecondsToCentimeters(duration1);
//fin calculo de cm
Serial.print("Centimetros 1: ");
Serial.print(cm1);
Serial.println();
//si los centimetros son menos de 100 quiere decir que hay un auto estacionado, si es mayor a 100 el estacionamiento esta desocupado
if (cm1 <= 100)
{
isparked1 = true;
Serial.print("Estacionado: SI 1");
Serial.println();
}
else if (cm1 > 100)
{
isparked1 = false;
Serial.print("Estacionado: NO 1");
Serial.println();
}
Serial.print("esperando 2 segundos");
Serial.println();
delay(2000);
Serial.print("haciendo nueva medicion 2");
Serial.println();
duration2 = ejecutarMedicion();
cm2 = microsecondsToCentimeters(duration2);
Serial.print("Centimetros 2: ");
Serial.print(cm2);
Serial.println();
if (cm2 <= 100)
{
isparked2 = true;
Serial.print("Estacionado: SI 2");
Serial.println();
}
else if (cm2 > 100)
{
isparked2 = false;
Serial.print("Estacionado: NO 2");
Serial.println();
}
if (isparked1 != isparked2)
{
Serial.print("isparked1 es distinto de isparked2");
Serial.println();
Serial.print("esperando 2 segundos");
Serial.println();
delay(2000);
Serial.println();
Serial.print("haciendo nueva medicion 3");
Serial.println();
duration3 = ejecutarMedicion();
cm3 = microsecondsToCentimeters(duration3);
Serial.print("Centimetros 3: ");
Serial.print(cm3);
Serial.println();
if (cm3 <= 100)
{
isparked3 = true;
Serial.print("Estacionado: SI 3");
Serial.println();
}
else if (cm3 > 100)
{
isparked3 = false;
Serial.print("Estacionado: NO 3");
Serial.println();
}
if (isparked2 == isparked3)
{
Serial.println();
Serial.print("isparked2 == isparked3");
Serial.println();
Serial.print("esperando 2 segundos");
Serial.println();
delay(2000);
Serial.print("haciendo nueva medicion 4");
Serial.println();
duration4 = ejecutarMedicion();
cm4 = microsecondsToCentimeters(duration4);
Serial.print("Centimetros 4: ");
Serial.print(cm4);
Serial.println();
if (cm4 <= 100)
{
isparked4 = true;
Serial.print("Estacionado: SI");
Serial.println();
}
else if (cm4 > 100)
{
isparked4 = false;
Serial.print("Estacionado: NO");
Serial.println();
}
if (isparked3 == isparked4)
{
Serial.print("isparked3 == isparked4");
Serial.println();
Serial.print("esperando 2 segundos");
Serial.println();
delay(2000);
Serial.print("haciendo nueva medicion 5");
Serial.println();
duration5 = ejecutarMedicion();
cm5 = microsecondsToCentimeters(duration5);
Serial.print("Centimetros 5: ");
Serial.print(cm5);
Serial.println();
if (cm5 <= 100)
{
isparked5 = true;
Serial.print("Estacionado: SI");
Serial.println();
}
else if (cm5 > 100)
{
isparked5 = false;
Serial.print("Estacionado: NO");
Serial.println();
}
if (isparked2 == isparked3 && isparked3 == isparked4 && isparked4 == isparked5)
{
Serial.print("Todos los valores de 4 mediciones son iguales");
Serial.println();
Serial.print("Conectando...");
Serial.println();
if (client.connect(server, 80))
{
Serial.print("CONECTADO");
Serial.println();
Serial.print("nuevo valor: ");
Serial.print(isparked5);
Serial.println();
Serial.print("haciendo la insercion del nuevo valor");
Serial.println();
client.print("GET /write_data.php?"); // This
client.print("value="); // This
client.print(isparked5);
if (isparked5 == 0)
{
Serial.println();
Serial.print("NO ESTACIONADO");
}
else
{
Serial.println();
Serial.print("SI ESTACIONADO");
}
client.println(" HTTP/1.1"); // Part of the GET request
client.println("Host: 192.168.0.11"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop(); // Closing connection to server
}
else
{
Serial.print("no hay conexion");
}
}
}
}
}
Serial.println();
Serial.print("terminando loop");
Serial.println();
}