Arduino Online/Offline Override

Hi there everyone! I am not really good with codes and Cayenne helped me a lot by simplifying it with the online dashboard (GREAT JOB GUYS!!!).

Info: Arduino mega, Ethernet Shield 5100, Jarduino Aquarium Controller (free software)

My project is an upgrade to an existing aquarium controller (Jarduino). I am planning to have a way to override the controller online if I need to. I think I can explain it more like this


if my device is “online” and override toggle is “on”
then, do these online istructions
else
do local instructions

Does that make sense? Like I said, I am bad with coding…
I just want it to continually check if it is online and if override is on. If not, then just do what it usually do.

The actual aquarium controller is pre-programmed (I just downloaded it from the net.) I am planning to just filter its output with another arduino mega using cayenne to override its signals (if needed) before they go to the breakout board.

Any help is much much appreciated!

Note; I am baaaad with programming so less coding is… well, more doable for me. Thanks everyone!

1 Like

The if online do Cayenne else do local is a good idea. The next time I have some time to code I’ll take a look to see if I can get something working for you.

1 Like

That would be totally awesome!!! I am trying to tinker here as well but i know you guys are going to beat me to it (no matter how hard I try), hahahahah! Coding is just not my field…

i feel your pain…

1 Like

Hi, is there such a “status” or a “flag” that I can detect to inform me if i am online or not? (quoted words cause I am not sure if they are called like that, hahaha). Something that would tell me my device is not connected so i can wrap my whole local commands in a huge “if” statement?

CAYENNE_CONNECTED() & CAYENNE_DISCONNECTED()

Although you need to go and make some changes in the background Blynk libraries to get the disconnected one working as its been commented out.

Use them to set a flag in your code and act on it - im just using them to turn a status LED on and off while i debug a problem

1 Like

just messing around

define a boolean first:

boolean onlineStatus = false;

then in your code insert these:

CAYENNE_CONNECTED(){
onlineStatus = true;
}

CAYENNE_DISCONNECTED(){
onlineStatus = false;
}

Then in your main loop act on the true/false status - simples!
Well maybe not but hope that helps :slight_smile:

2 Likes

But my prev post stands about having to edit the libaries to get CAYENNE_DISCONNECTED working

1 Like

Yes!!! I think that just might do it!!! I will try it and hopefully it will yield success!

Are those lines/commands/function/library located within “arduino/libraries/cayenne/…ethernet*” (sorry not in front of the computer right now). It is the cayenne ethernet library that i call from the example code right (#include cayenne ethernet something something$? Hoping for the best! Will post my petty endeavor later. Thanks tim2!

Oh yeah! I appreciate the detailed explanation! Excited to try it later! Tnx again

not in front of the right PC at the moment - do a text search of the library files for “blynkondisconnect” (from memory) to find the right file and uncomment as required. Also uncomment CAYENNE_DISCONNECTED in the KEYWORDS file
If you get stuck let me know and i’ll post again on monday

ok - found it - file is BlynkProtocol.h

do a find and remove the comments on ALL the lines like this: //BlynkOnDisconnected();
There are 5 or six or so from memory

I made the functions you mentioned and edited the library.
But when I put my device offline, it just keeps reconnecting (which is good…) but does not seem to go though my local instructions…
Here’s the code I used. Also, the " CAYENNE_DISCONNECTED" does not turn orange color unlike " CAYENNE_CONNECTED" (I did un-commented it on the library as you mentioned.

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

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "o6vy3e061m";
boolean onlineStatus=false;
void setup()
{
	Serial.begin(9600);
	Cayenne.begin(token);
}
   CAYENNE_CONNECTED(){onlineStatus=true;}
   CAYENNE_DISCONNECTED(){onlineStatus=false;}
void loop()
{
   if (onlineStatus==true)
   {Cayenne.run();
   Serial.print("Online");} 
   else{ 
    digitalWrite(23,digitalRead(22));
    digitalWrite(25,digitalRead(24));
    digitalWrite(27,digitalRead(26));
    digitalWrite(29,digitalRead(28));
    digitalWrite(31,digitalRead(30));
    digitalWrite(33,digitalRead(32));
    digitalWrite(35,digitalRead(34));
    digitalWrite(37,digitalRead(36));
    digitalWrite(39,digitalRead(38));
    digitalWrite(41,digitalRead(40));
    digitalWrite(43,digitalRead(42));
    digitalWrite(45,digitalRead(44));
    digitalWrite(47,digitalRead(46));
    digitalWrite(49,digitalRead(48));
    digitalWrite(51,digitalRead(50));
    digitalWrite(53,digitalRead(52));
    Serial.print("Offline");        //Test if the program enters else..
   }   
} 

Serial.print(“Offline”)-does not appear on my serial monitor
I know there are a LOT MORE efficient ways to do this than my codes, but again, I am not really good at this, so the simpler the better, hehe

You need to uncomment it in the KEYWORDS file as well to get it to go orange.

As for the rest…i havent tested or explored what was discussed any further. I only use it turn switch a LED to show locally the status of the device. It will take some testing to work out best way to do it.
Scrap all the digitalwrites and get the abolute basics running first as expected (ie serial output of online/offline or switching a led based on status) and work from there

Here’s my update… I uncommented the KEYWORDS file and got the disconnect function to turn yellow, then i turned everything to basics. I was able to make it do EXACTLY as i want if i used the manual example (the one where i manually set a static IP). Here is the working code… It prints “offline” when the net is unplugged then “online” when it is connected.

#define CAYENNE_DEBUG           
#define CAYENNE_PRINT Serial       
#include <CayenneEthernet.h>        
#include <CayenneEthernetW5500.h> 
#include <CayenneEthernetW5200.h> 

char token[] = "xxxxxxxxxx";
boolean onlineStatus=false;
byte arduino_mac[] = { 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX }; //actual values replaced, just to be safe when i post it...
IPAddress arduino_ip(xxx, xxx, x, xx);
IPAddress dns_ip(x, x, x, x);
IPAddress gateway_ip(xxx, xxx, x, x);
IPAddress subnet_mask(xxx, xxx, xxx, x);

void setup()
{
	Serial.begin(9600);
	Cayenne.begin(token, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
}
CAYENNE_CONNECTED(){onlineStatus=true;}
CAYENNE_DISCONNECTED(){onlineStatus=false;}
void loop()
{
	Cayenne.run();
  if (onlineStatus==true){
        Serial.print("ONLINE ");}
  else{
        Serial.print("Local ");}
  }

But when i tried it for the regular ethernet example (i used the required libraries etc as the default example), it hangs on “getting IP” when network is unplugged… Any work around for that??? Code below if it helps:

#define CAYENNE_DEBUG       
#define CAYENNE_PRINT Serial
#include <CayenneEthernet.h>

char token[] = "xxxxxxxxxx";
boolean onlineStatus=false;
void setup()
{	Serial.begin(9600);
	Cayenne.begin(token);
}
   CAYENNE_CONNECTED(){onlineStatus=true;}
   CAYENNE_DISCONNECTED(){onlineStatus=false;}
void loop()
{
  Cayenne.run();
  if (onlineStatus==true){
    Serial.print("Online ");}
  else{
    Serial.print("Off ");}
} 

This one hangs on “getting IP” when network is unplugged, while if I used static IP it works fine… but i think i would need the non-static ip route… Any suggestions??? ^____^

Can you get the basic cayenne ethernet example to run?

yep, using the cayenne ethernet example, no issues, but if i use it without the network plugged in, it stay at “getting IP”…

should drop to DHCP Failed! after a while thats what mine does