8000 GitHub - JiekangHuang/am7020_IoT_ATcommand: AM7020 MQTT(S), HTTP(S) Library(Protocol Stack on SIM7020E)
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

AM7020 MQTT(S), HTTP(S) Library(Protocol Stack on SIM7020E)

License

Notifications You must be signed in to change notification settings

JiekangHuang/am7020_IoT_ATcommand

Repository files navigation

AM7020 MQTT(S)/HTTP(S) Arduino Library

AM7020 (SIMCOM SIM7020E) MQTT(S), HTTP(S) Library(Protocol Stack on SIM7020E) AM7020

AM7020

Declare nbiot instance using:

#define SerialAT       Serial2
#define AM7020_RESET   5
SIM7020NB nb(SerialAT, AM7020_RESET);

Initialize nb and connect to NBIOT base station:

void nbConnect(void)
{
    Serial.println(F("Initializing modem..."));
    while (!nb.init() || !nb.nbiotConnect(APN, BAND)) {
        Serial.print(F("."));
    }; 
    Serial.print(F("Waiting for network..."));
    while (!nb.waitForNetwork()) {
        Serial.print(F("."));
        delay(5000);
    }
    Serial.println(F(" success"));
}

Check NBIOT connection status:

if (!nb.chkNet()) {
    nbConnect();
}

MQTT(S)

Declare instance using:

  • MQTT
SIM7020EMQTT  mqtt(SerialAT);
  • MQTTS
    You can use the openssl command to get the Server CA.
openssl s_client -connect {HOSTNAME}:{PORT} -showcerts
const char root_ca[] PROGMEM = {"-----BEGIN CERTIFICATE-----\\r\\n"
                                "MIIEAzCCAuugAwIBAgIUBY1hlCGvdj4NhBXkZ/uLUZNILAwwDQYJKoZIhvcNAQEL\\r\\n"
                                ...
                                "-----END CERTIFICATE-----"};
SIM7020EMQTTS mqtts(SerialAT, root_ca);

Publish and subscribe:

mqtt.publish(MQTT_TOPIC, message);

void callback(const char *msg)
{
    Serial.print(MQTT_TOPIC ": ");
    Serial.println(msg);
}
mqtt.subscribe(MQTT_TOPIC, callback);

Listen for messages from the broker:

mqtt.procSubs();

HTTP(S)

Declare instance using:

  • HTTP
SIM7020EHTTP  http(SerialAT, HTTP_SERVER);
  • HTTPS
    You can use the openssl command to get the Server CA.
openssl s_client -connect {HOSTNAME}:{PORT} -showcerts
const char root_ca[] PROGMEM = {"-----BEGIN CERTIFICATE-----\n"
                                "MIIEdTCCA12gAwIBAgIJAKcOSkw0grd/MA0GCSqGSIb3DQEBCwUAMGgxCzAJBgNV\n"
                                ...
                                "-----END CERTIFICATE-----"};
SIM7020EHTTPS https(SerialAT, HTTP_SERVER, root_ca);

HTTP Get and Post:

http.get(HTTP_GET_API);
http.post(HTTP_POST_API, "application/json", "{\"value\": \"POST\"}");

About

AM7020 MQTT(S), HTTP(S) Library(Protocol Stack on SIM7020E)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0