No Data Arriving in Thingspeak Channel


I am trying t set up a cellular Particle Boron and Sensor to track my well water levels but the data is not showing up in Thingspeak. I have activated and flashed code to the device, created a Particle account, a Thingspeak account (and channel), and a Webhook. Things mostly work as they should and I can even see the data from the sensor in my Particle Console "Events", but nothing seems to arrive in the Thingspeak Channel. I am looking for technical advice.
Graham
Graham
Graham on 9 Jan 2024
Here are two examples from Data Import/Export. This is what is being recieved by Thingspeak.
<feed>
<created-at type="dateTime">2024-01-08T09:48:53Z</created-at>
<entry-id type="integer">11</entry-id>
<field1>Water Depth</field1>
</feed>
<feed>
<created-at type="dateTime">2024-01-08T09:49:56Z</created-at>
<entry-id type="integer">12</entry-id>
<field1>Water Depth</field1>
</feed>
Christopher Stapels
Christopher Stapels on 9 Jan 2024
The field value there is "Water Depth" so that explains why ThingSpeak cannot plot it. You will need to send a number instead of the value label.
Graham
Graham on 8 Jan 2024 (Edited on 9 Jan 2024)
Thank you for pointing me in the right direction. Non numeric data may be the problem as it is consistent with what I see in the events arriving in Thingspeak. I'm still not sure where to go from here. I am using a sensor to measure water levels. I have some coding and arduino experience but new to Particle and Thingspeak so struggling to tie them all together. The code was previously written and used with Particle and Thingspeak for rural well water level monitoring in eastern Canada so I'm not sure why it isn't working this time around? Here is the code that was provided with the device and I have successfully flashed to a Particle Boron:
// Coded by J.Drage, 20-Feb-2022
STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));
SYSTEM_THREAD(ENABLED);
SystemSleepConfiguration config;
//--------------------------------------------------------------------------
// Define Boron pins:
//--------------------------------------------------------------------------
#define WLsensor_power D2 // Pin D2 powers the water level sensor on
#define WLsensor_data D3 // Pin D3 is data output from the water level sensor
//--------------------------------------------------------------------------
// Variables to be entered by user
//--------------------------------------------------------------------------
int MeasureTime=86400000; // Time between water level measurements; entered by user (milliseconds)
int ConnectTime=120000; // Time allowed for Particle Boron to connect to the cloud before going back to sleep; should not be less than 90000; entered by user (milliseconds)
double Datum=3.0; // Datum elevation; typically top of well casing is used; entered by user (metres)
double HangDown=0.5; // Distance from datum to sensor; entered by user (metres)
//--------------------------------------------------------------------------
// Variables NOT entered by user
//--------------------------------------------------------------------------
int MeasureTime2=(MeasureTime-60000); // Subtract 60000 milliseconds from MeasureTime to account for time needed to connect to the cloud; this keeps the measurement time to about the same time each day
double WLSensorValue=0; // Reading from water level sensor (mm)
double Depth=0; // Depth to water; measured by the sensor and then converted from mm to m (metres)
double GWelevation=0; // Water table elevation; calculated by code (metres)
void setup() {
//--------------------------------------------------------------------------
// Configure pins on the Boron
//--------------------------------------------------------------------------
pinMode(WLsensor_power, OUTPUT);
pinMode(WLsensor_data, INPUT);
Serial.begin(9600);
PMIC().disableCharging();
config.mode(SystemSleepMode::ULTRA_LOW_POWER).duration(MeasureTime2);
}
void loop() {
//--------------------------------------------------------------------------
// Check to see if Boron is connected to the cloud, if not then go to sleep to preserve the batteries
//--------------------------------------------------------------------------
restart:
if( !Particle.connected() ) {
Particle.connect();
if ( !waitFor(Particle.connected, ConnectTime) ) {
System.sleep(config);
goto restart;
}
}
//--------------------------------------------------------------------------
// Read the water level from the sensor
//--------------------------------------------------------------------------
digitalWrite(WLsensor_power, HIGH);
delay(1s);
WLSensorValue = pulseIn(WLsensor_data, HIGH);
digitalWrite(WLsensor_power, LOW);
Depth = (WLSensorValue/1000);
GWelevation = (Datum-HangDown-Depth);
//--------------------------------------------------------------------------
// Check to see if the water depth is out of sensor range and if so, go to sleep without reporting the result; sensor range is 0.3-5m (5m model) or 0.5-10m (10m model)
//--------------------------------------------------------------------------
if (Depth<0.31) {
delay(2s);
System.sleep(config);
goto restart;
}
if (Depth>4.99) {
delay(2s);
System.sleep(config);
goto restart;
}
//--------------------------------------------------------------------------
// Send the water level data to ThingSpeak.com
//--------------------------------------------------------------------------
Particle.publish("Water Depth", String(GWelevation, 2), PRIVATE);
delay(2s);
System.sleep(config);
goto restart;
}
Christopher Stapels
Christopher Stapels on 9 Jan 2024 (Edited on 10 Jan 2024)
Loooking at your code, it seems that the webhook may be defined incorrectly.
I think this line sends data to particle, then particle scans the data and forwards it to the ThingSpeak API if it is written correctly.
Particle.publish("Water Depth", String(GWelevation, 2), PRIVATE);
I think your webhook is configured to write the first argument of data to the channel, when I think you will want to write the second argument (String(GWelevation,2) instead.
Graham
Graham on 6 Jan 2024
Am I supposed to do something with the Read or Write Channel feeds somewhere? It shows the data has arrived in Thingspeak but is not being plotted on the graph. I have inserted the Write API key in the Particle Console Integration, as well as Field1 as Water Depth. I think I am missing a step?
Christopher Stapels
Christopher Stapels on 8 Jan 2024
Use the read data api to export the data and see the format you are getting. Generally when you see the last update increment but no data in the plots it means you have non numeric data coming in.
If that fails, I would start with the write API and make sure you can manually update your channel vis web browser. You can get the write data syntax from the API keys tab of your channel view.