TinyZero WINC1500 Connected but no data

Hi, I am have a bit of trouble - I have created a device, and I can see that when I run my code it get’s connected but no data ever shows up and of course after some timeout- it disconnects.

Hardware:
TinyZero
TinyWIFI WINC1500

I used the example code that should have populated a new widget with time

I enabled Cayenne_ Debug, and can see that indeed it does get connected to Cayenne, but no data ever shows up in the dashboard, and again it times out after a while.

The program I’m running gets to this line of code and does the log in to Cayenne

Cayenne.begin(username, password, clientID);

And as I said, Cayenne_Debug shows this:

[10598] Connecting to mqtt.mydevice.com:1883
[11954] Connected

and the web page shows that indeed I’m connected (ie no yellow box with “offline” at the top of the page until it times out.

Looking for advice as to what I may be overlooking

can you share the code you are using.

It’s the basic timer program, modified to work with the TinyZero, but here it is less the credentials:

/*
This example shows how to connect to Cayenne using an Ethernet W5100 shield 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. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  2. Compile and upload the sketch.
  3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
    */
    #include <Wire.h> // For I2C communication with sensor
    #include <WiFi101.h> // For connecting to WiFi
    #define CAYENNE_DEBUG // Uncomment to show debug messages
    #define CAYENNE_PRINT SerialUSB // Comment this out to disable prints and save space
    #include <CayenneMQTTWiFi101.h> // Cayenne library to connect to transmit data

/*********************** EDIT THIS SECTION TO MATCH YOUR INFO /
// WiFi network information
char ssid[] =“REMOVED”;
char wifiPassword[] ="REMOVED ";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[]=“REMOVED”;
char password[]=“REMOVED”;
char clientID[]=“REMOVED”;
/
************************************************************/

// Define Serial object based on which TinyCircuits processor board is used.
#if defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#else
#define SerialMonitorInterface Serial
#endif

void setup() {
SerialMonitorInterface.begin(9600);
Wire.begin();
WiFi.setPins(8, 2, A3, -1); // VERY IMPORTANT FOR TINYCIRCUITS WIFI SHIELD

while (!SerialMonitorInterface); // Will halt program until the Serial Monitor is opened

// Connect to WiFi and Cayenne
connectWifi();

// Print out the local IP address
SerialMonitorInterface.println("");
SerialMonitorInterface.println("IP address: ");
IPAddress ip = WiFi.localIP();
SerialMonitorInterface.println(ip);
Cayenne.begin(username, password, clientID);

}

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());

}

// 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”);
}

// This function goes through the steps to connect to WiFi using the WiFi101 library
void connectWifi(void){
// Connect to Wifi network:
SerialMonitorInterface.print("Connecting Wifi: ");
SerialMonitorInterface.println(ssid);
WiFi.begin(ssid, wifiPassword);

// Loop until connection is secured
while (WiFi.status() != WL_CONNECTED){
SerialMonitorInterface.print(".");
delay(500);
}

// Success message and put WiFi in low power mode to save energy
WiFi.maxLowPowerMode();
SerialMonitorInterface.println("");
SerialMonitorInterface.println(“WiFi connected”);

}

The code looks correct. can you try this code and share the entire serial monitor output :-

/*
This example shows how to connect to Cayenne using an Ethernet W5100 shield 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:

Set the Cayenne authentication info to match the authentication info from the Dashboard.
Compile and upload the sketch.
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 SerialUSB // Comment this out to disable prints and save space
#include <Wire.h> // For I2C communication with sensor
#include <WiFi101.h> // For connecting to WiFi
#include <CayenneMQTTWiFi101.h> // Cayenne library to connect to transmit data
/*********************** EDIT THIS SECTION TO MATCH YOUR INFO /
// WiFi network information
char ssid[] =“REMOVED”;
char wifiPassword[] ="REMOVED ";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[]=“REMOVED”;
char password[]=“REMOVED”;
char clientID[]=“REMOVED”;
/************************************************************/

// Define Serial object based on which TinyCircuits processor board is used.
#if defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#else
#define SerialMonitorInterface Serial
#endif

void setup() {
SerialMonitorInterface.begin(9600);
Wire.begin();
WiFi.setPins(8, 2, A3, -1); // VERY IMPORTANT FOR TINYCIRCUITS WIFI SHIELD

while (!SerialMonitorInterface); // Will halt program until the Serial Monitor is opened

// Connect to WiFi and Cayenne
connectWifi();

// Print out the local IP address
SerialMonitorInterface.println("");
SerialMonitorInterface.println("IP address: ");
IPAddress ip = WiFi.localIP();
SerialMonitorInterface.println(ip);
Cayenne.begin(username, password, clientID);

}

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());
Cayenne.virtualWrite(1, millis());
SerialMonitorInterface.println("SEND");

}

// 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”);
}

// This function goes through the steps to connect to WiFi using the WiFi101 library
void connectWifi(void){
// Connect to Wifi network:
SerialMonitorInterface.print("Connecting Wifi: ");
SerialMonitorInterface.println(ssid);
WiFi.begin(ssid, wifiPassword);

// Loop until connection is secured
while (WiFi.status() != WL_CONNECTED){
SerialMonitorInterface.print(".");
delay(500);
}

// Success message and put WiFi in low power mode to save energy
WiFi.maxLowPowerMode();
SerialMonitorInterface.println("");
SerialMonitorInterface.println(“WiFi connected”);

}

Here is the output- still just connects and no data then disconnects after 30 seconds (or so, I didn’t time it out)

FWIW- I did successfully connect and send data using the BLYNK app- so it’s not a hardware problem.

Connecting Wifi: REDACTED

WiFi connected

IP address:
10.0.1.157
[6291] IP: 10.0.1.157
[6292] Connecting to mqtt.mydevices.com:1883
[6879] Connected

try this code:

// Define Serial object based on which TinyCircuits processor board is used.
#if defined(ARDUINO_ARCH_SAMD)
  #define SerialMonitorInterface SerialUSB
#else
  #define SerialMonitorInterface Serial
#endif

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT SerialMonitorInterface  // Comment this out to disable prints and save space
#include <CayenneMQTTWiFi101.h>

// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "wifiPassword";

// 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);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

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");
}

I had to modify what you sent to get the serial port to work- SerialMonitorInterface wasn’t being enabled so no connections happened at all.

So I added this code:

WiFi.setPins(8, 2, A3, -1); // VERY IMPORTANT FOR TINYCIRCUITS WIFI SHIELD

while (!SerialMonitorInterface); // Will halt program until the Serial Monitor is opened

just before

Serial.begin(9600);

That now allows the wifi to connect.

I also enabled Debug, Same result, On my serial monitor I can see that it Logs into my wifi, then connects to Cayenne, Web page indicates that there is a connection ( yellow bar at top goes away) but nothing populates on the webpage, After about 30Sec, it then “times out” and disconnects as evidenced by the yellow banner at the top of the web page saying “Offline”

you can try with the pubsub library here is an example code https://github.com/spacefolder/esp8266-MQTT-v1/blob/master/esp8266-MQTT-v1.cpp and combine it with wifi101 library.

Thank you for your help, I had to make quite a few changes to that pubsub example, but finally, I was able to push data to the dashboard. I’m still uncertain as to why the CayenneMQTTWiFi101 functions didn’t work, but I’ll take any success I can get. Thanks again

Glad to hear that worked. it would be great if you could share the working code with the cayenne community.

Here is the code I used to test the PubSubClient interface to Cayenne dashboard
It’s not very clean, but it worked.

/*
This example shows how to connect to Cayenne  and send sample data.
This sketch displays Arduino uptime on Cayenne dashboard
Using a TinyZero processor
sketch to test MQTT interface to Cayenne using PubSubClient,  
 modified from esp82660MQTT code found here:
  https://github.com/spacefolder/esp8266-MQTT-v1/blob/master/esp8266-MQTT-v1.cpp

Steps:
1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
2. Compile and upload the sketch.
3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/

/************************************************************************/
// Libraries 
#include <Wire.h>  
#include <WiFi101.h>      // For connecting to WiFi
#include <PubSubClient.h>//for publishing to MQTT


/*********************** EDIT THIS SECTION TO MATCH YOUR INFO *************************/
//   Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
#define MQTT_SERVER     "mqtt.mydevices.com"
#define MQTT_SERVERPORT 1883
#define MQTT_USERNAME " REDACTED" 
#define MQTT_PASSWORD "REDACTED"
#define CLIENT_ID "REDACTED" 

/************************************************************************************/
// Define "topic"ie data,  linked to the Cayenne Dashboard in this case= Time on Cayenne Channel 1
#define MQTT_TOPIC_TIME   "v1/" MQTT_USERNAME "/things/" CLIENT_ID "/data/1"

// Create a client instance for PubSubClient to use 
WiFiClient    espClient;              
PubSubClient  client(espClient);

// WiFi network information
const char* ssid = "REDACTED" //your wifi network SSID
const char* Password = "REDACTED" //your wifi password

//Variables to hold time information 
long    timeStampNow;
long    timeStampLastMsg = 0;
long    timeIs;

// Define a datatype to store the mqtt message, up to 50 bytes.
char    msg[50];                 // 50 BYTES  

// Define Serial object based on which TinyCircuits processor board is used.
#if defined(ARDUINO_ARCH_SAMD)
  #define SerialMonitorInterface SerialUSB
#else
  #define SerialMonitorInterface Serial
#endif


//Setup and connect to serial port, wifi and Cayenne 
void setup() {
  SerialMonitorInterface.begin(9600);
  Wire.begin();
  WiFi.setPins(8, 2, A3, -1); // VERY IMPORTANT FOR TINYCIRCUITS WIFI SHIELD

while (!SerialMonitorInterface); // ***Will halt program until the Serial Monitor is opened***
  SerialMonitorInterface.println("DEBUG: Entering startup");
  
  // Connect to WiFi  
  connectWifi();
 
  // Print out the local IP address on monitor to verify logged in
  SerialMonitorInterface.println("");
  SerialMonitorInterface.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  SerialMonitorInterface.println(ip);

// Initialize MQTT PubSub Library
  client.setServer(MQTT_SERVER, MQTT_SERVERPORT);
  // send message to monitor that we've set server and port for Cayenne 
   SerialMonitorInterface.println("DEBUG: Sever and port set ");
}

void loop() {
  //check to see if actually connected to Cayenne, if not then connect;
  if (!client.connected()) {                            
    reconnect();
}
  // If connected, perform PubSubClient 
client.loop();
// now do something useful, like read the time   
// Publish time readings every 5 seconds (5000ms)
  timeStampNow = millis();
  if (timeStampNow - timeStampLastMsg > 5000) {    // Publish interval in milliseconds
    // Reset the counter
    timeStampLastMsg = timeStampNow;
    // Jump to the actual function to read and publish time.
    dealWithTime();
  }
// not sure this delay is needed but it was in the example code
  delay(10);
}

// Functions
void reconnect() {                                  
  // If  is disconnected from the mqtt server, try to reconnect.
  while (!client.connected()) {
    SerialMonitorInterface.print("DEBUG: Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect(CLIENT_ID, MQTT_USERNAME, MQTT_PASSWORD)) {
      SerialMonitorInterface.println("connected");
} else {
      SerialMonitorInterface.print("failed, rc=");
      SerialMonitorInterface.print(client.state());
      SerialMonitorInterface.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
  SerialMonitorInterface.println("DEBUG: exit connection loop ");
}
// This function goes through the steps to connect to WiFi using the WiFi101 library
void connectWifi(void){
  // Connect to Wifi network:
  SerialMonitorInterface.print("Connecting Wifi: ");
  SerialMonitorInterface.println(ssid);
  WiFi.begin(ssid, Password);

  // Loop until connection is secured
  while (WiFi.status() != WL_CONNECTED){
    SerialMonitorInterface.print(".");
    delay(500);
  }

  // Success message and put WiFi in low power mode to save energy
  WiFi.maxLowPowerMode();
  SerialMonitorInterface.println("");
  SerialMonitorInterface.println("WiFi connected");
}
  
// Function that handles time, and publishes to Cayenne Dashboard.

void dealWithTime() {
  
  SerialMonitorInterface.print(" Requesting time...");
  //get time 
  timeIs = (millis()/1000); 
  SerialMonitorInterface.println("DONE");

  // Construct the mqtt message following Cayenne's rules, according to the Docs..
  // Send Sensor data -> Topic: v1/username/things/clientID/data/channel  
 
  String mqtt_message =  String(timeIs);
  // Convert the string into a Char Array
  mqtt_message.toCharArray(msg, 20);
  SerialMonitorInterface.print("Publish message: ");
  SerialMonitorInterface.println(msg);
  // Finally! Publish the time to Cayenne Dashboard, Channel 1.
  client.publish(MQTT_TOPIC_TIME, msg);

    
}

thanks for sharing.