Good day!
I am playing around with FreeRTOS on a (an) Uno and it works pretty well but there are some unique issues. The one big issue I am having is in using a string or a char array in an RTOS task.
In each task, which I have two of them, I have some blinking leds/relays to show me that the FreeRTOS tasks are working.
I have declared in my code:
#include <Arduino_FreeRTOS.h>
#include <LiquidCrystal_I2C.h>
#include <Ethernet.h>
#include <EthernetICMP.h>
// Setup IP addresses to ping
IPAddress machineIP[] = {IPAddress(192,168,100,1), IPAddress(192,168,100,30), IPAddress(192,168,100,25), IPAddress(192,168,100,165)};
// Setup Machine Names
char *MachineNames[] = {"Tucson Router", "Nebula VPN", "Tucson PiHole", "Tucson FreePBX"};
// define the two tasks
void PingMyServers( void *pvParameters );
void WebServerStartUp( void *pvParameters );
In my setup() I have;
void setup()
// Now set up two tasks to run independently.
xTaskCreate(
PingMyServers
, "Blink3Relays" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL
, 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL );
xTaskCreate(
WebServerStartUp
, "Blink1Relay"
, 128 // Stack size
, NULL
, 1 // Priority
, NULL );
My WebServerStartUp task works fine as there is not much to go wrong. However, my PingMyServers task will run as long as I do not try to use or print a member of my MachineNames[ ]. So...
void PingMyServers(void *pvParameters) // This is a task. PingMyServers
{
(void) pvParameters;
for (;;)
{
// Blink smoe relays for fun and ensure the task is functioning
digitalWrite(relay[1], HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(relay[2], HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(relay[3], HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(relay[3], LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(relay[2], LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(relay[1], LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS );
//*************** TRY THE PING STUFF **************************************
lcd.setCursor(0,0);
lcd.print("Pinging:");
numFailures = 0;
numSuccesses = 0;
// Start the Pinging the machine
for (int z = 0; z <= 3; z++)
{
ClearLine(1);
ClearLine(2);
ClearLine(3);
lcd.setCursor(0,1);
// lcd.print(MachineNames[z]); // << THIS DOES NOT WORK. Ever!
lcd.print("My Machine name"); // << THIS WORKS
lcd.setCursor(0, 2);
lcd.print(machineIP[z]); // THIS WORKS EVERY TIME!!
vTaskDelay( 1000 / portTICK_PERIOD_MS );
} //End of the Ping Stuff Loop
}
}
Simply, lcd.print(MachineNames[z]); does not work and as a matter of fact it hoses up both tasks so nothing is running. Both tasks do not run.
AND... if I try to declare an actual string array,
String MachineNames[] = {"Tucson Router", "Nebula VPN", "Tucson PiHole", "Tucson FreePBX"};
And leave the tasks alone so that they worked as before neither task run.
In a nutshell, how do I get a string or char array to display when in a 'for' in my FreeRTOS task? Somehow I wouldn't think this would be rocket science but I am stumped.
Any help will be most appreciated.
John