Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to AWS using GPRS #13

Open
mazeemsk opened this issue Apr 21, 2020 · 1 comment
Open

Connecting to AWS using GPRS #13

mazeemsk opened this issue Apr 21, 2020 · 1 comment

Comments

@mazeemsk
Copy link

mazeemsk commented Apr 21, 2020

Hi,
I want to use this library to connect to AWS using SIM800L GPRS module.My code connected to internet but does not connect to AWS...kindly guide as I am a newbie. here is my code.

#define TINY_GSM_MODEM_SIM800
#include <SoftwareSerial.h>
#include <TinyGsmClient.h>
#include <PubSubClient.h>

//Enter values in secrets.h ▼

#include "secrets.h"

SoftwareSerial SerialAT(16,17); // RX, TX


//Network details
const char apn[]  = "";
const char user[] = "";
const char password[] = "";

const int  MQTT_PORT = 8883;
const char MQTT_SUB_TOPIC[] = "$aws/things/" THINGNAME "/shadow/update";
const char MQTT_PUB_TOPIC[] = "$aws/things/" THINGNAME "/shadow/update";


TinyGsm modem(SerialAT);
//TinyGsmClient client(modem);
TinyGsmClientSecure client(modem);
PubSubClient mqtt(client);

void setup()
{
  Serial.begin(9600);
  SerialAT.begin(9600);
  
  Serial.println("System start.");
  modem.restart();
  Serial.println("Modem: " + modem.getModemInfo());
  Serial.println("Searching for telco provider.");
  if(!modem.waitForNetwork())
  {
    Serial.println("fail");
    while(true);
  }
  Serial.println("Connected to telco.");
  Serial.println("Signal Quality: " + String(modem.getSignalQuality()));

  Serial.println("Connecting to GPRS network.");
  if (!modem.gprsConnect(apn, user, password))
  {
    Serial.println("fail");
    while(true);
  }
  Serial.println("Connected to GPRS: " + String(apn));
  
  
  mqtt.setServer(MQTT_HOST, MQTT_PORT);
  mqtt.setCallback(mqttCallback);
  Serial.println("Connecting to MQTT Broker: " + String(MQTT_HOST));
  while(mqttConnect()==false) continue;
  Serial.println();
  
  
  
    
}

void loop()
{
  if(Serial.available())
  {
    delay(10);
    String message="";
    while(Serial.available()) message+=(char)Serial.read();
    mqtt.publish(MQTT_PUB_TOPIC, message.c_str());
  }
  
  if(mqtt.connected())
  {
    mqtt.loop();
  }
}

boolean mqttConnect()
{
  if(!mqtt.connect("GsmClientTest"))
  {
    Serial.print(".");
    return false;
  }
  Serial.println("Connected to broker.");
  mqtt.subscribe(MQTT_SUB_TOPIC);
  return mqtt.connected();
}
@oussama415
Copy link

Hi,

Did you find any solution about this !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants