[SOLVED] Code is putting photon into breathing green light

Mod Edit (@harrisonhjones): Solution: See this post

James Savko makes a washing machine detector (http://www.jamessavko.com/2016/01/19/washing-machine-notification-sensor/).

I have all the hardware and his code forces my particle photon to go into breathing green light. I have to go into safemode in order to re-flash which is inconvenient.

Here is the code I am referring to:
I am using 0.6.0 firmware.

// This #include statement was automatically added by the Spark IDE.
#include "thingspeak/thingspeak.h"

const int PiezoSensor = A1; // the piezo is connected to analog pin 1
const int threshold = 1;
const long interval = 17000;           // interval at which to ping Thingspeak (milliseconds)
unsigned long previousMillis = 0;        // will store last time we reported to thingspeek

int sensorReading = 0; // variable to store the value read from the sensor pin. From 0 to 1023
int ticks = 0;

ThingSpeakLibrary::ThingSpeak thingspeak ("Channel-API-Key");

void setup() {
      pinMode(PiezoSensor, INPUT);
}

void loop() {

    unsigned long currentMillis = millis();
    sensorReading = analogRead(PiezoSensor);

    if (sensorReading >= threshold) {
        bool valSet = thingspeak.recordValue(1, String(sensorReading, DEC));

        if (currentMillis - previousMillis >= interval) {
            ticks = (currentMillis - previousMillis);
            bool valSet = thingspeak.recordValue(2, String(ticks, DEC));
            bool valsSent = thingspeak.sendValues();
            if(valsSent) {
                previousMillis = currentMillis;
                ticks = 0;
            }
        }
    }
    delay(100);

}

I am unsure what to do.
Thank you!

I’ve narrowed down the problem to be

bool valsSent = thingspeak.sendValues();

I have no idea how to fix this.

There appear to be two thingspeak libraries in the WebIDE. Which are you using? Either way, you’ll want to reach out to the library owner.

You’re right, there are two thingspeak libraries. How do I find the owners of each library?

Hi @quesopones

The official one looks like this:

And the github link points to the official github repo here:

1 Like

That sounds like when trying to send values, the code is blocking and preventing your Photon from processing it’s background tasks. So eventually after about 10-15 seconds the Photon will drop back to breathing green.

This is likely because your Thingspeak account is not setup properly I’d guess. Did you by any chance replace Channel-API-Key with your own?

@bko
Thank you, I am currently using that library

@BDub
Yes, I have replaced the Channel-API-Key with my own. Is there a tutorial that shows how to properly set up a thingspeak account with a particle photon?
Thanks!

You just need these lines with your secret numbers--you don't seem to be using the channel number.

/*
  *****************************************************************************************
  **** Visit https://www.thingspeak.com to sign up for a free account and create
  **** a channel.  The video tutorial http://community.thingspeak.com/tutorials/thingspeak-channels/ 
  **** has more information. You need to change this to your channel, and your write API key
  **** IF YOU SHARE YOUR CODE WITH OTHERS, MAKE SURE YOU REMOVE YOUR WRITE API KEY!!
  *****************************************************************************************/
unsigned long myChannelNumber = 31461;
const char * myWriteAPIKey = "LD79EOAAWRVYF04Y";

Try using this example to get started:

https://github.com/mathworks/thingspeak-particle/blob/master/firmware/examples/WriteMultipleVoltages.ino

2 Likes

@bko
Thank you, that solved the problem!

3 Likes