Unable to send data to cloud

Hi, I've been trying out the Arduino Cloud and dashboard (first time using these and first time using MKR GSM 1400). I've been unsuccessful in transmitting the sensor readings to the cloud and aim to use the MKR GSM 1400 wirelessly. Do I have to pack the data before transmission? I'm very lost and any guidance is appreciated!!

/*  
  CloudPercentage moisture_Sensor1;
  CloudPercentage moisture_Sensor2;
  float salinity_Sensor;
  CloudTemperatureSensor temperature_Sensor;

  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 <ArduinoLowPower.h>
#include <MKRGSM.h>
#include "thingProperties.h"

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess(true);     // include a 'true' parameter for debug enabled
GSMServer server(80); // port 80 (http default)

#include <Wire.h>
#define D6T_ADDR 0x0A
#define D6T_CMD 0x4C  // for D6T-44L-06/06H, D6T-8L-09/09H, for D6T-1A-01/02

#define N_ROW 1
#define N_PIXEL 1
#define N_READ ((N_PIXEL + 1) * 2 + 1)

#define PINNUMBER "0000"
#define GPRS_APN       "APN"
#define GPRS_LOGIN     "User"
#define GPRS_PASSWORD  "Password"

uint8_t rbuf[N_READ];
double ptat;
double pix_data[N_PIXEL];

uint8_t calc_crc(uint8_t data) {
  int index;
  uint8_t temp;
  for (index = 0; index < 8; index++) {
    temp = data;
    data <<= 1;
    if (temp & 0x80) {
      data ^= 0x07;
    }
  }
  return data;
}

bool D6T_checkPEC(uint8_t buf[], int n) {
  int i;
  uint8_t crc = calc_crc((D6T_ADDR << 1) | 1);  // I2C Read address (8bit)
  for (i = 0; i < n; i++) {
    crc = calc_crc(buf[i] ^ crc);
  }
  bool ret = crc != buf[n];

  return ret;
}

/** <!-- conv8us_s16_le {{{1 --> convert a 16bit data from the byte stream.
*/
int16_t conv8us_s16_le(uint8_t* buf, int n) {
  uint16_t ret;
  ret = (uint16_t)buf[n];
  ret += ((uint16_t)buf[n + 1]) << 8;
  return (int16_t)ret;   // and convert negative.
}

char Server[] = "arduino.cc/iot/things/d6c4256e-09a9-4e62-92cb-699cafe6c089/serial-monitor";
char path[] = "/";
int port = 80; // port 80 is the default for HTTP

void setup() {
  Serial.begin(9600);

  Wire.begin();  // i2c master
  delay(220);
  
 Serial.println("Starting Arduino web client.");
  // connection state
// connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
 Serial.println("Connected to GPRS network");

  // start server
  server.begin();

  //Get IP.
  IPAddress LocalIP = gprs.getIPAddress();
  Serial.println("Server IP address=");
  Serial.println(LocalIP);

  
  int i = 0;
  int16_t itemp = 0;

  // 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(2);
  ArduinoCloud.printDebugInfo();
  }

void loop() {
  ArduinoCloud.update();
  
  int conducVal;
  const int dry = 764; // value for dry sensor
  const int wet = 379; // value for wet sensor

  int sensorVal = analogRead(A0);
  int sensorVal2 = analogRead(A1);
  conducVal = analogRead(A2)*(5/1024);
  // Sensor has a range of 379 to 764
  // We want to translate this to a scale or 0% to 100%

  int moisture_Sensor1 = map(sensorVal, wet, dry, 100, 0);
  int moisture_Sensor2 = map(sensorVal2, wet, dry, 100, 0);

  int i = 0;
  int16_t itemp = 0;

  // Read data via I2C
  // I2C buffer of "Arduino MKR" is 256 buffer. (It is enough)
  memset(rbuf, 0, N_READ);
  Wire.beginTransmission(D6T_ADDR);  // I2C slave address
  Wire.write(D6T_CMD);               // D6T register
  Wire.endTransmission();
  Wire.requestFrom(D6T_ADDR, N_READ);
  while (Wire.available()) {
    rbuf[i++] = Wire.read();
  }
  D6T_checkPEC(rbuf, N_READ - 1);

  //Convert to temperature data (degC)
  ptat = (double)conv8us_s16_le(rbuf, 0) / 10.0;
  for (i = 0; i < N_PIXEL; i++) {
    itemp = conv8us_s16_le(rbuf, 2 + 2 * i);
    pix_data[i] = (double)itemp / 10.0;
  }

client.beginWrite() ; {
  client.write(int moisture_Sensor1, 12);
  client.write(int moisture_Sensor2, 12);
  client.write(pix_data[10]);
  client.write(int conducVal, 12);
  client.endWrite();
  
  }
}

Post the AT log

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.