PIR Motion detector with ESP8266

Hi @jeremy,
We understand the frustration. We are looking into this now & trying to see if we can isolate the problem. So this is why I was asking to see if the issue also occurs for you with Arduino.

But as @bestes mentioned, try the custom widget option for now, while we fix the other widget.

Thanks.
-Jesse

Hey folks,

So far having same issue. This time I took a NodeMCU and configured it with a luminosity sensor and confirmed that was all working unconnected to Cayenne. Then I added code to connect to Cayenne and the board now shows in my profile and is connected to my WiFi fine.

However, I am still unable to associate any widgets within Cayenne for the sensor. Same issue as I had with the previous build using the Sparkfun Thing (not Dev board). See attached image. Select device option is grayed out, and I get a red circle:

no-symbol

So, still pretty frustrated :slight_smile:

can you add a new device using “Bring Your Own thing” and add the MQTT credential into the below code and see if nodemcu gets connected and you see a value widget. once done share a screenshot of the dashboard and then we can move forward with luminosity sensor.

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. 

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "wifiPassword";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

unsigned long lastMillis = 0;

void setup() {
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
	Cayenne.loop();

	//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
	if (millis() - lastMillis > 10000) {
		lastMillis = millis();
		//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
		Cayenne.virtualWrite(0, lastMillis);
}
}

Click on the Value/Gauge/Line Chart widget and then try to add your device.

~Benny

shramiksalgaonkar,

I was not having issues connecting the NodeMCU - as you can see from the screen shot above. So yes, using your code I can connect the board.generic

And I still can’t assign anything…

Can’t grayed out…

add device using Bring Your Own Thing to get MQTT credentials.

Hi @jeremy,

For BYOT and ESP devices, you would need to use Custom Widgets only. So try adding one from the custom widgets option & see if you’re able to select your ESP device:

Let us know if this works for you.
Thanks.
-Jesse

Added Custom Widget, got MQTT code… but it doesn’t load, and I did check to see that I have the library installed.

error: CayenneMQTTClient.h: No such file or directory
#include “CayenneMQTTClient.h”
^
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

can you give a try to the code i posted above.

Yes, Shramik, I can connect with your code, but that isn’t much different from other attempts:

test

Folks, I can see where you can add a custom widget, but the issue seems to be this code:

/**

  • @file SimplePublish.c
  • Simplified example app for using the Cayenne MQTT C library to publish example data.
    */

#include “CayenneMQTTClient.h”

That simply won’t run. And why - if I assign the channel and the other widget parameters - why are they not included in your code? Doesn’t make sense to use your wizard in Step 1. I am better off coding that part myself with the working CayenneMQTTESP8266.h library. Still have yet to try this, but seems a better plan than CayenneMQTTClient.h which doesn’t compile.

So here is the final solution I came up with:

// JJD 2/21/18 Working IR sensor added manually (not using Cayennne wizard)
// jeremydeprisco.com

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

//Light stuff
#define lightPin A0
#define VIRTUAL_PIN V1 //

// WiFi network info.
char ssid = “YOURNETWORK”;
char wifiPassword = “YOURPW”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “Get from Cayenne”;
char password = “Get from Cayenne”;
char clientID = “Get from Cayenne”;

int lightBright = 0; // for IR

int previousState = -1;
int currentState = -1;
unsigned long previousMillis = 0;
unsigned long lastMillis = 0;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
getLightData();
displayData();

//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(0, lastMillis);
Cayenne.virtualWrite(3, lightBright);
}
}

// * Get Light Sensor data
void getLightData(void)
{
lightBright = 0;
delay (500);
int N = 3;
for(int i = 0; i < N; i++) // read sensor “N” times and get the average
{
lightBright += analogRead(lightPin);
delay(150);
}
//digitalWrite (lightPinVcc, LOW);
lightBright = lightBright/N;
lightBright = map(lightBright, 380, 0, 0, 100); // not sure what this does yet
}

// * Display data at Serial Monitor
void displayData(void)
{
if (lightBright > 0) {
Serial.print(" Dark: “);
Serial.println(lightBright);
}
else {
Serial.print(” Light: ");
Serial.println(lightBright);
}
}

CayenneSuccess

1 Like