Greetings all, new forum member here.
I’m having a problem with one of my two Particle.Function’s on a Photon board.
One of my two Particle.Function’s is working flawlessly every time I call it, but my second Function only works for a while, then goes unresponsive. It typically works for several days, sometimes a week or so, then stops. Even when the second function stops working the first always continues working appropriately. Simply re-flashing my code to the board, or power cycling the board, gets things working again for about a week then the problem occurs again.
Calling the second function from the web console or via curl gives me identical results. Curl even gives me a 200 OK response, but then I never see the result of my Particle.function actually being run.
Below is the code running on my board (just ‘eth_mac’ has been obfuscated). The ‘tvToggle’ Particle.function is my function that always seems to work, whereas ‘wakeHome’ is the Particle.function that works for a while and stops.
I initially suspected I perhaps had a memory leak in the code someplace, but I’m not sure that fits given my ‘tvToggle’ always seems to work. Perhaps this is a bug with the Particle Cloud? Perhaps I’m doing something wrong in my code?
Thanks for any help in advance!
(‘tvToggle’ function turns my TV/stereo on/off, ‘wakeHome’ function is a WoL client to turn my PC on)
#include <IRTransmitter/IRTransmitter.h>
#define IR_PIN D1
#define LED_PIN D7
unsigned int avr_pwr[] = {3350,1650,450,400,450,400,400,1250,450,400,400,1250,450,400,400,1250,450,400,400,450,400,1200,450,450,400,400,450,1200,450,1200,450,400,450,400,400,450,400,450,400,400,400,450,400,450,400,400,400,1250,450,400,400,1250,450,400,400,450,400,400,450,1200,450,400,450,1200,450,400,450,400,400,450,400,400,450,400,400,450,400,400,450,400,400,450,400,1200,450,450,400,400,400,450,400,1250,400,400,450,450,400,400,400};
unsigned int tv_pwr[] = {4500,4450,600,1650,550,1650,600,1650,550,550,550,550,600,550,550,550,550,550,600,1650,550,1650,550,1700,550,550,550,550,600,500,600,550,550,550,550,550,600,1650,550,550,550,550,600,550,550,550,550,550,600,500,600,1650,550,550,600,1650,550,1650,600,1650,550,1650,600,1650,550,1650,600};
IRTransmitter transmitter(IR_PIN, LED_PIN);
int tvToggle(String command) {
if (command=="on") {
transmitter.Transmit(tv_pwr, sizeof(tv_pwr) / sizeof(tv_pwr[0]));
transmitter.Transmit(avr_pwr, sizeof(avr_pwr) / sizeof(avr_pwr[0]));
return 0;
}
else {
return -1;
}
}
#define REPEAT_MAC 16
#define MAGIC_HEADER_LENGTH 6
byte eth_mac[] = {0XDE,0xAD,0xBE,0xEF,0xDE,0xAD};
uint16_t port = 4999;
IPAddress ip(192,168,1,255);
UDP udp;
int wakeHome(String command) {
if (command=="on") {
udp.beginPacket(ip, port);
for (int i = 0; i < MAGIC_HEADER_LENGTH; i++) {
udp.write(0xFF);
}
for (int i = 0; i < REPEAT_MAC; i++) {
udp.write(eth_mac, sizeof eth_mac);
}
udp.endPacket();
return 0;
}
else {
return -1;
}
}
void setup() {
Particle.function("tv",tvToggle);
Particle.function("wakeHome", wakeHome);
udp.begin(port);
}