Georgi Angelov
Published

LTE NB Arduino for Quectel BC66

The world's first real Arduino core for LTE IoT CAT/NB ( Quectel BC66 )

EasyProtip204
LTE NB Arduino for Quectel BC66

Things used in this project

Hardware components

MediaTek Labs Quectel BC66
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Arduino

Arduino czmfvpr59h

Code

Simple MQTT

Arduino
void loop() {
  LOG("\n[APP] Narrow Band Level: %d,\n", receiveLevel());
  
  static int count = 0;
  int rc;
  MqttNetwork n = { 0 };
  MqttClient c = { 0 };
  MQTTPacket_connectData options = MQTTPacket_connectData_initializer;
  MQTTMessage message;
  n.mqttread = mqtt_read;
  n.mqttwrite = mqtt_write;
  n.disconnect = mqtt_disconnect;
  NewNetwork(&n);
  rc = ConnectNetwork(&n, (char*) "m15.cloudmqtt.com", (char*) "13717"); // or IP  "34.238.150.50"
  if (rc != 0) {
    LOG("[ERROR] ConnectNetwork( %d )\n", rc);
    goto END;
  }
  LOG("[APP] MQTT Connected\n");
  MQTTClient(&c, &n, 5000, tx, 1024, rx, 1024);
  options.MQTTVersion = 3;
  options.clientID.cstring = (char*) dev.imei;
  options.username.cstring = (char*) "cbimusme";
  options.password.cstring = (char*) "gc5-N2fucr_y";
  options.keepAliveInterval = 60;
  options.cleansession = 1;
  rc = MQTTConnect(&c, &options); // error?
  LOG("[API] MQTTConnect( %d )\n", rc);
  message.qos = QOS0;
  snprintf(payload, 256, "{\"text\":\"BC66 OpenCPU + Arduino = Love\",\"rssi\":\"%d dBm\",\"status\":\"connected\",\"ai\":\"%d mV\",\"di\":\"%s\"}\0",
           receiveLevel(),
           analogRead(0),
           ++count % 2 == 0 ? "ON" : "OFF"
          );
  message.payload = payload;
  message.payloadlen = strlen((char*) message.payload);
  rc = MQTTPublish(&c, (char*) "bc66-mqtt-demo", &message); // error?
  LOG("[APP] MQTTPublish( %d )\n", rc);
  MQTTDisconnect(&c);
  LOG("[APP] MQTT Disconnected\n");

END:
  LOG("[APP] Waithing...\n");
  delay(60 * 1000);
}

Credits

Georgi Angelov

Georgi Angelov

2 projects • 2 followers

Comments

Add projectSign up / Login