CAYENNE_OUT_DEFAULT----Widget adding errors

can you try the bare minimum code, without any sensor code. So that we can first check that we can atleast connect.

I did remove all the sensor info byt again could not connect.

Once I commented the Cayenne.begin(username, password, clientID, SerialAT, apn, gprsUser, gprsPass, GSM_PIN); command, the modem begun to try to connect to the internet. Below is the Setup loop containing the comment I commented

void GSM_setup() {

Serial.begin(115200);
Serial1.begin(115200);
// Set console baud rate
SerialMon.begin(115200);
//delay(10);

Serial.println(“Check 1”);

// !!!
// Set your reset, enable, power pins here
// !!!

SerialMon.println(“Wait…”);

// Set GSM module baud rate
//TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX);
SerialAT.begin(9600);
delay(3000);

// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println(“Initializing modem…”);
modem.init();
// modem.init();

String modemInfo = modem.getModemInfo();
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);

#if TINY_GSM_USE_GPRS
// Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
#endif

//Cayenne.begin(username, password, clientID, SerialAT, apn, gprsUser, gprsPass, GSM_PIN);
}

when i mean the basic example i mean this code, without any modification

/*
This example shows how to connect to Cayenne using a GSM device and send/receive sample data.
The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Install the TinyGSM library (https://github.com/vshymanskyy/TinyGSM) from the Arduino Library Manager.
2. Set the Cayenne authentication info to match the authentication info from the Dashboard.
3. Uncomment the correct GSM modem type and set the GSM connection info, if needed.
4. Compile and upload the sketch.
5. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

// Uncomment your modem type:
 //#define TINY_GSM_MODEM_SIM800
// #define TINY_GSM_MODEM_SIM808
 #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_UBLOX
// #define TINY_GSM_MODEM_BG96
// #define TINY_GSM_MODEM_A6
// #define TINY_GSM_MODEM_A7
// #define TINY_GSM_MODEM_M590
// #define TINY_GSM_MODEM_ESP8266
// #define TINY_GSM_MODEM_XBEE

#include <CayenneMQTTGSM.h>

// This sketch uses a software serial connection.
#include <SoftwareSerial.h>
//SoftwareSerial gsmSerial(2, 3); // RX, TX
// If you are using a device that supports a hardware serial (Mega, Leonardo, etc.) and prefer to use
// that you can comment out the above lines and uncomment the one below.
#define gsmSerial Serial1

// GSM connection info.
char apn[] = ""; // Access point name. Leave empty if it is not needed.
char gprsLogin[] = ""; // GPRS username. Leave empty if it is not needed.
char gprsPassword[] = ""; // GPRS password. Leave empty if it is not needed.
char pin[] = ""; // SIM pin number. Leave empty if it is not needed.

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

void setup() {
	Serial.begin(9600);
	// Auto-detect the GSM serial baud rate. You can manually set it instead if you want to save a bit of space.
	TinyGsmAutoBaud(gsmSerial);
	Cayenne.begin(username, password, clientID, gsmSerial, apn, gprsLogin, gprsPassword, pin);
}

void loop() {
	Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
	// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
	Cayenne.virtualWrite(0, millis());
	// Some examples of other functions you can use to send data.
	//Cayenne.celsiusWrite(1, 22.0);
	//Cayenne.luxWrite(2, 700);
	//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
	//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

Hello,
\I did try it and get the following Serial Output

[[15922] IP: x.x.x.x
[15923] Connecting to mqtt.mydevices.com:1883
[22250] Connected
[25568] Disconnected
[25569] Connecting to mqtt.mydevices.com:1883
[25606] Network connect failed
[28175] Connected
[1020] Initializing modem
[1105] Waiting for network
[1120] Connecting to GPRS
[9275] Connected to GPRS
[9293] IP: x.x.x.x
[9294] Connecting to mqtt.mydevices.com:1883
[84328] Network connect failed
[87700] Connected
[104836] Disconnected
[104836] Connecting to mqtt.mydevices.com:1883
[106716] Connected
[171311] Disconnected
[171312] Connecting to mqtt.mydevices.com:1883
[174074] Connected
[234468] Disconnected
[234468] Connecting to mqtt.mydevices.com:1883

I do not get any connections shown in Cayenne dashboard thoiugh

add a new device to dashboard and use the new client id in the code. Also add #define CAYENNE_DEBUG

Προγρεσσ μαδε,

By disabling Cayenne.loop(); command, sensor readings returnwed to normal print speed and acuracy.

Any ideas on a solution/workaround?

Dear Shramik,

Adding a new device seems to have solved the issue and the system has succesfully connected to Cayenne.

One issue I am facing is that now I am not getting correct readings from my MPU 6050 accelerometer connected to SCA and SCL pins of a MEGA , when running the sensor script combined with the sensor code part.

Please note that the sensor script works fine when used on its own.
I have also disabled the //#define CAYENNE_DEBUG and
//#define CAYENNE_PRINT Serial comands.

Any ideas anyone?

let gets clear, that the basic code works and connect to cayenne. Can you share serial monitor screenshot with #define CAYENNE_DEBUG

Yes,

Of course, please find below

========================================
Calculating gyro offsets
DO NOT MOVE MPU6050…
Done!
X : -4.45
Y : 2.73
Z : -0.19
Program will start after 3 seconds
========================================[11378] Initializing modem
[11462] Waiting for network
[11476] Connecting to GPRS
[104688] Connected to GPRS
[104705] IP: 10.152.173.171
[104706] Connecting to mqtt.mydevices.com:1883
[106106] Connected
[106720] Publish: topic 4, channel 65534, value Arduino Mega, subkey , key
[106772] Publish: topic 6, channel 65534, value ATmega2560, subkey , key
[106851] Publish: topic 7, channel 65534, value 16000000, subkey , key
[106923] Publish: topic 5, channel 65534, value 1.3.0, subkey , key
[106994] Publish: topic 8, channel 65534, value GSM, subkey , key
angleX : -3.67 angleY : 3.98 angleZ : -2.94
angleX : -3.58 angleY : 3.76 angleZ : -2.94
angleX : -3.51 angleY : 3.53 angleZ : -2.95
angleX : -3.43 angleY : 3.30 angleZ : -2.95
angleX : -3.36 angleY : 3.08 angleZ : -2.95
angleX : -3.29 angleY : 2.87 angleZ : -2.95
angleX : -3.21 angleY : 2.66 angleZ : -2.96
angleX : -3.13 angleY : 2.45 angleZ : -2.96
angleX : -3.06 angleY : 2.26 angleZ : -2.96
angleX : -3.00 angleY : 2.05 angleZ : -2.96
angleX : -2.93 angleY : 1.87 angleZ : -2.96
angleX : -2.86 angleY : 1.69 angleZ : -2.96
angleX : -2.80 angleY : 1.50 angleZ : -2.96
angleX : -2.74 angleY : 1.32 angleZ : -2.96

without sensor code.

Output below

[1020] Initializing modem
[1105] Waiting for network
[1120] Connecting to GPRS
[92123] Connected to GPRS
[92143] IP: 10.153.34.219
[92144] Connecting to mqtt.mydevices.com:1883
[96376] Connected

with this

[1020] Initializing modem
[1105] Waiting for network
[1119] Connecting to GPRS
[5085] Connected to GPRS
[5103] IP: x.x.x.x
[5104] Connecting to mqtt.mydevices.com:1883
[80136] Network connect failed
[88576] Connected
[89273] Publish: topic 4, channel 65534, value Arduino Mega, subkey , key
[89327] Publish: topic 6, channel 65534, value ATmega2560, subkey , key
[89399] Publish: topic 7, channel 65534, value 16000000, subkey , key
[90459] Publish: topic 5, channel 65534, value 1.3.0, subkey , key
[91465] Publish: topic 8, channel 65534, value GSM, subkey , key
[93717] Publish: topic 1, channel 0, value 93717, subkey , key
[103349] Connection ok
[109503] Publish: topic 1, channel 0, value 109502, subkey , key
[113810] Connection ok

looks good. I hope you don’t get any frequent network disconnect issue.

So next, step is to read the MPU reading on the mega and show on serial monitor.

Yes.,

I have no issues woith connections. The issues I have is that when the Cayenne.loop() is included the sensor readings are false or do not change even when the sensor is moved?

Any ideas on this?

that is because this is synchronous execution. It check the connection. You can do one thing is just change the time interval using Cayenne.loop(10) or but again when this is called the MPU wont be able to give reading.

This cannot be changed as a behavior although Iam using a MEGA?

At some point I got readings of a small angle change equal to 700!!! The sensor;s behavior is altered complketely

Shramik,

I did set the Cayenne.loop(10) script but unfortunately did not get any change in operation. Any thoughts?

can you share the code and serial monitor output.

i already explained here

There is not other way to deal with this? This makes the sensor’s readings unreliable I am afraid.

Would it be possible to store the sensor readings in a variable and transmit this variable to Cayenne each time Cayenne.loop(10) is called?
Would this be a workaround?