0

I am having trouble connecting my MKR GSM to the Arduino Cloud platform. My code is shown below:

The .ino file.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Bin One"
  https://create.arduino.cc/cloud/things/acdff5db-845e-42f4-851d-6b8367a3c258 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudTemperatureSensor temperature2;
  CloudTemperatureSensor temperature3;
  CloudTemperatureSensor temperature1;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_Sensor.h>

// everything to control the sensors
#define DHTPIN1            5
#define DHTPIN2            4
#define DHTPIN3            6

#define DHTTYPE           DHT22

DHT_Unified dht1(DHTPIN1, DHTTYPE);
DHT_Unified dht2(DHTPIN2, DHTTYPE);
DHT_Unified dht3(DHTPIN3, DHTTYPE);

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(4);
  ArduinoCloud.printDebugInfo();
  
  dht1.begin();
  dht2.begin();
  dht3.begin();

  sensor_t sensor;
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  // Get temperature event
  sensors_event_t event1;
  dht1.temperature().getEvent(&event1);
  
  temperature1 = event1.temperature;
  
  // Get temperature event
  sensors_event_t event2;
  dht2.temperature().getEvent(&event2);
  
  temperature2 = event2.temperature;
  
  // Get temperature event
  sensors_event_t event3;
  dht3.temperature().getEvent(&event3);
  
  temperature3 = event3.temperature;
  
  delay(3600000);
}

The .h file

// Code generated by Arduino IoT Cloud, DO NOT EDIT.

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>


const char THING_ID[]      = "acdff5db-845e-42f4-851d-6b8367a3c258";

const char GPRS_APN[]      = SECRET_APN;
const char PINNUMBER[]     = SECRET_PIN;
const char GPRS_LOGIN[]    = SECRET_USERNAME;
const char GPRS_PASSWORD[] = SECRET_PASSWORD;


CloudTemperatureSensor temperature2;
CloudTemperatureSensor temperature3;
CloudTemperatureSensor temperature1;

void initProperties(){

  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(temperature2, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(temperature3, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(temperature1, READ, ON_CHANGE, NULL);

}

GSMConnectionHandler ArduinoIoTPreferredConnection(PINNUMBER, GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD);

The output I am getting from serial is

SIM card ok
GPRS.attachGPRS(): 4
Sending PING to outer space...
GPRS.ping(): -2
PING failed
Retrying in  "500" milliseconds

I have tried this code in multiple locations (I live in a rural area so I thought the connection might be the problem), and with a battery connected to the MKR GSM.

When it wasn't working with the sim card I have specifically to use with the Arduino I used the sim in my cell phone. Neither has worked as of yet.

I have previously used the MKR GSM and a sim card bought for it to send text messages while monitoring a grain bin for months at a time, so I think it must be something I am doing wrong with connecting to the Arduino Cloud.

Thanks in advance!

1
  • Hey. I have a solution working right now. It seems that the delays in the code were making it hard to connect. I removed almost all of them and now it works better, but I am still planning to get a better antenna since the signal where I am is bad. Feb 27 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.