Cloud Variables have not been updating by Thing to Thing communication

  • I have been leaving it update for couple week, but nothing happened.
  • I need to send data from my IPhone's Sensor (Location, Compass.) to ESP32-S3_DevKitC-1 for calculation code.
  • Lately, I just tested by ESP32 read Variables from ESP32-S3_DevKitC-1 but nothing happened.
  • The widgets in dashboard are properly work. It can read data from both of Board and IPhone.









Code In ESP32-S3

    /*   
modified on Sep 27, 2020
Modified by MohammedDamirchi from https://github.com/mikalhart/TinyGPSPlus
Home 
*/ 

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "thingProperties.h"
#include <WiFi.h>
#include <QMC5883LCompass.h>

// Mode Control (MODE)
const byte qmc5883l_mode_stby = 0x00;
const byte qmc5883l_mode_cont = 0x01;
// Output Data Rate (ODR)
const byte qmc5883l_odr_10hz  = 0x00;
const byte qmc5883l_odr_50hz  = 0x04;
const byte qmc5883l_odr_100hz = 0x08;
const byte qmc5883l_odr_200hz = 0x0C;
// Full Scale Range (RNG)
const byte qmc5883l_rng_2g    = 0x00;
const byte qmc5883l_rng_8g    = 0x10;
// Over Sample Ratio (OSR)
const byte qmc5883l_osr_512   = 0x00;
const byte qmc5883l_osr_256   = 0x40;
const byte qmc5883l_osr_128   = 0x80;
const byte qmc5883l_osr_64    = 0xC0;

/*
  This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
  It requires the use of SoftwareSerial, and assumes that you have a
  9600-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 18, TXPin = 17;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;
QMC5883LCompass compass;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

const char* ssid = "Surt_2.4G";
const char* password = "*************";


void setup()
{
  Serial.begin(9600);
  ss.begin(GPSBaud);
  WiFi.begin(ssid, password);
  Wire.begin(21,16);


  Serial.println(F("DeviceExample.ino"));
  Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
  
  Serial.println("Connecting to WiFi network...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected to WiFi network!");
  
  compass.init();
  //compass.setADDR(byte b);
  //compass.setMode(byte mode,          byte odr,           byte rng,        byte osr        );
  //compass.setMode(qmc5883l_mode_cont, qmc5883l_odr_200hz, qmc5883l_rng_8g, qmc5883l_osr_512);
  //compass.setSmoothing(byte steps, bool adv);
  //compass.setCalibration(int x_min, int x_max, int y_min, int y_max, int z_min, int z_max);
  compass.setCalibration(-573, 1851, 0, 5170, 0, 3295);
  //compass.setReset();
   
  // 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()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
  
  double  Lat = gps.location.lat() ;
  double  Long = gps.location.lng() ;

  coordinates = {Lat, Long};
  
  //cloudTimeVariable = ArduinoCloud.getLocalTime();
  
  //float Compass;
  //Serial.println(Compass);
  
  ArduinoCloud.update();
  // Your code here 
  
}

void displayInfo()
{
  //GPS
  Serial.print(F("Location: ")); 
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10 ) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.println();  
  delay(500);
  
  //COMPASS
  int x_value;
  int y_value;
  int z_value;
  //int azimuth;  // 0° - 359°
  byte bearing; // 0 - 15 (N, NNE, NE, ENE, E, ...)
  char direction[strlen("NNE") + 1];
  char buffer[strlen("X=-99999 | Y=-99999 | Z=-99999 | A=259° | B=15 | D=NNE") + 1]; 
   
  compass.read(); // Read compass values via I2C

  x_value   = compass.getX();
  y_value   = compass.getY();
  z_value   = compass.getZ();
  azimuth   = compass.getAzimuth(); // Calculated from X and Y value 
  bearing   = compass.getBearing(azimuth);
   
  compass.getDirection(direction, azimuth);
  direction[3] = '\0';

  sprintf(buffer,
          "X=%6d | Y=%6d | Z=%6d | A=%3d° | B=%02hu | %s",
          x_value,
          y_value,
          z_value,
          azimuth,
          bearing,
          direction                                           );
  Serial.println(buffer);
}
/*
  Since IphoneCompass is READ_WRITE variable, onIphoneCompassChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onIphoneCompassChange()  {
  // Add your code here to act upon IphoneCompass change
}

Hi.

is this line compiling properly?

  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

I would propose

  while (ss.available() > 0) {
    if (gps.encode(ss.read()) {
      displayInfo(); }
}

but first, you should test your board and data exchange with Iot cloud in a simpler way, like sharing few values not coming from another peripheral but simply light a led on your board.

EDIT: sorry, I just read (again) and see you have proper data exchange with IOT cloud.

1 Like

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