Good morning @Scruffr:
Yes, indeed, I did. The code is long so was reluctant to show. Here it is:
==============================================================================
//==============================================================================
//SYSTEM_THREAD(ENABLED);
//==============================================================================
//=======================================================================================================
// ThingSpeak.h, ThingSpeak.cpp, QueueList.h, Utilities.cpp, Utilities.h
#include "ThingSpeak.h"
// This #include statement was automatically added by the Particle IDE.
#include <PublishManager.h>
PublishManager<> publishManager;
//=======================================================================================================
// Main Settings
//=======================================================================================================
String verNum = "1.15";
int baseNum = 4444; //Electron #
int myTimeZone = -4;
int showLCD = 1;
int myPlatform; //=6 Photon, =10 Electron
int a, b, c;
String myData;
//========================================================================================================
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>
TCPClient client;
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
// This #include statement was automatically added by the Particle IDE.
#include "Utilities.h"
int count = 0;
//========================================================================================================
/* Data Format
---------------------------------------------------
1) All messages start with "$$" and end with "^"
*/
//===========================================================================================================
//Screen
//===========================================================================================================
int countLCD = 0;
int refreshLCD = 20;
//===========================================================================================================
int unitNum; //Xenon Unit sending the data
int inform = 0; //=1 if message was sent
int congChanged = 0; //=1 congestion changed from congested to clear or vice versa
int goPublish = 0; //=1 Particle Publish, =0 do NOT
int numSensors = 0; //Total number of sensors sending data
int numNuSensors = 0; //Total number of sensors after zeroing
int mySensors[] = {0, 0, 0, 0};
int myPsuSpeed[] = {0, 0, 0, 0};
int myCongestion[] = {0, 0, 0, 0};
int psuSpeed; //average psuedo speed from sensors
int numBatch = 99; //Total number of cars + trucks per sensor before sending
bool allCongested = false;
int numCongested = 0 ; //Number of congested lanes
int congestion = 0;
int sensorInd; //Index of base within array
int myTrucks[] = {0, 0, 0, 0};
int myCars[] = {0, 0, 0, 0};
int totalTrucks[] = {0, 0, 0, 0}; //Total Trucks for each sensor
int totalCars[] = {0, 0, 0, 0}; //Total Cars for each sensor
int myTime[] = {0, 0, 0, 0};
int myTimeInt = 0;
int oldTraffic;
int number_of_truck = 0, number_of_car = 0;
int total_Trucks = 0, total_Cars = 0;
int curTrucks = 0, curCars = 0;
String lastStat = "None";
String lastComm = "None";
int numOcc = 0;
//===========================================================================================================
int writeEach = 0; //=0 do not write each record to disk, =1 write each vehicle
NonBlockDelay d;
//===========================================================================================================
int currentHour;
int currentMinute;
unsigned long startTime; //Start operations millis()
unsigned long dayMS = (86400 * 1000); //milliseconds in a day
unsigned long lastMS; //last time in milliseconds
unsigned long resetTime = 60 * (60 * 1000); //Reset if no info in 60 minutes
unsigned long transmitTime = 0; //last successful transmission (after checking connected)
unsigned long infoTime; //last message time received from Xenon
unsigned long updateTime = 60 * (60 * 1000); //Heartbeat 60 minutes if (goPublish ==1 )
//===========================================================================================================
/* Thingspeak */
// https://www.mathworks.com/help/thingspeak/use-photon-client-to-publish-to-a-channel.html
char writeAPIKey[] = "XENUOR3"; // Change this to your channel Write API Key.
long channelID = 632; // Change this to your channel number.
unsigned long thingConTime = 0; //last time data was sent to Thingspeak
struct thingMessageS {
int baseNum;
int unitNum;
String number_of_truck;
String number_of_car;
String total_Trucks2;
String total_Cars2;
int psuSpeed;
int congestion;
unsigned long timeInterval;
};
thingMessageS thingMessage;
//========================================================================================================
//https://playground.arduino.cc/Code/QueueList
#include "QueueList.h"
QueueList <thingMessageS> queue;
int queueCount = 0;
const unsigned long transmitInt = 20 * 1000UL;
//===========================================================================================================
//https://forum.arduino.cc/index.php?topic=246654.0
union cvt {
float val;
unsigned char b[4];
} x;
//===========================================================================================================
String tMessage;
//void myHandler(const char *event, const char *data)
void myHandler(const char *event, const char *data)
{
//Serial.printlnf("event=%s data=%s", event, data ? data : "NULL");
infoTime = millis();
myData = data ;
parseRecData(data);
if (goPublish == 1 ) publishManager.publish("RECEIVED", "$$,33," + String(baseNum) + ", Data =" + String(data) + "," + String(numSensors) + "," + String(numNuSensors) + "," + String(Time.timeStr()) + "," + "^");
}
//===========================================================================================================