Sharp GP2Y1010AU0F - dust sensor


#1

Codes for different boards and shields.
All codes only work with MQTT.

Arduino_Industrial_101.txt (1.2 KB)
EthernetShieldW5200.txt (2.0 KB)
ArduinoYun.txt (1.5 KB)
EthernetShieldW5100.txt (2.0 KB)
EthernetShieldW5500.txt (2.0 KB)
ManualConnection.txt (2.9 KB)
WiFiShield.txt (2.1 KB)
WiFi101Shield.txt (2.1 KB)

Sample from the Cayenne Dashboard.


#2

Hi,

I tried to use the WiFiShield example for the Sharp GP2Y1010AU0F in combination with a Wemos D1 mini but I run into compile errors.

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoDefines.h:127:0,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:21,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:21,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/DetectDevice.h:227:10: warning: #warning "Cannot detect board type" [-Wcpp]

         #warning "Cannot detect board type"

          ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/CayenneMQTTClient.h:24:0,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMessage.h:32,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneHandlers.h:29,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoDefines.h:128,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:21,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:21,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:328:30: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]

      const size_t getCount() const {

                              ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:21:0,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h: In member function 'void CayenneArduinoMQTTClient::connect()':

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:59:63: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

    if (!NetworkConnect(&_network, CAYENNE_DOMAIN, CAYENNE_PORT)) {

                                                               ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:21:0,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h: At global scope:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:292:7: warning: unused parameter 'channel' [-Wunused-parameter]

  void syncVirtual(int channel)

       ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25:0,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h: In member function 'void CayenneMQTTWiFiClient::begin(const char*, const char*, const char*, const char*, const char*)':

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:49:33: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

    WiFi.begin(ssid, wifiPassword);

                                 ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:23:0,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\WiFi\src/WiFi.h:79:9: error:   initializing argument 1 of 'int WiFiClass::begin(char*, const char*)' [-fpermissive]

     int begin(char* ssid, const char *passphrase);

         ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25:0,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:52:19: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

    WiFi.begin(ssid);

                   ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:23:0,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\WiFi\src/WiFi.h:60:9: error:   initializing argument 1 of 'int WiFiClass::begin(char*)' [-fpermissive]

     int begin(char* ssid);

         ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25:0,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:41:7: warning: unused variable 'status' [-Wunused-variable]

   int status = WL_IDLE_STATUS;

       ^

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:21:0,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h: In instantiation of 'static void CayenneArduinoMQTTClient::publishData(CayenneTopic, unsigned int, const T&, const char*, const char*) [with T = const __FlashStringHelper*; CayenneTopic = CayenneTopic]':

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:125:66:   required from here

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:333:3: error: call of overloaded 'add(const char*&, const __FlashStringHelper* const&)' is ambiguous

   values.add(subkey, data);

   ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:333:3: note: candidates are:

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/CayenneMQTTClient.h:24:0,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMessage.h:32,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneHandlers.h:29,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoDefines.h:128,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:21,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:21,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:106:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4] <near match>

   inline void add(const char* unit, const int value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:106:15: note:   no known conversion for argument 2 from 'const __FlashStringHelper* const' to 'int'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:121:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, unsigned int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4] <near match>

   inline void add(const char* unit, const unsigned int value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:121:15: note:   no known conversion for argument 2 from 'const __FlashStringHelper* const' to 'unsigned int'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:136:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, long int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4] <near match>

   inline void add(const char* unit, const long value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:136:15: note:   no known conversion for argument 2 from 'const __FlashStringHelper* const' to 'long int'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:151:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, long unsigned int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4] <near match>

   inline void add(const char* unit, const unsigned long value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:151:15: note:   no known conversion for argument 2 from 'const __FlashStringHelper* const' to 'long unsigned int'

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:21:0,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h: In instantiation of 'static void CayenneArduinoMQTTClient::publishData(CayenneTopic, unsigned int, const T&, const __FlashStringHelper*, const __FlashStringHelper*) [with T = float; CayenneTopic = CayenneTopic]':

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:159:52:   required from 'void CayenneArduinoMQTTClient::virtualWrite(unsigned int, const T&, const __FlashStringHelper*, const __FlashStringHelper*) [with T = float]'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:221:68:   required from here

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:349:3: error: no matching function for call to 'CayenneMQTT::DataArray<>::add(const __FlashStringHelper*&, const float&)'

   values.add(subkey, data);

   ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:349:3: note: candidates are:

In file included from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/CayenneMQTTClient.h:24:0,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMessage.h:32,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneHandlers.h:29,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoDefines.h:128,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:21,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFiClient.h:21,

                 from C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTWiFi.h:25,

                 from C:\Users\Marco\Documents\Arduino\GP2YDustWemosCayenne\GP2YDustWemosCayenne.ino:5:

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:65:8: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, const char*, bool, bool) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]

   void add(const char* unit, const char* value, bool unitInFlash = false, bool valueInFlash = false) {

        ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:65:8: note:   no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const char*'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:106:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]

   inline void add(const char* unit, const int value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:106:15: note:   no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const char*'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:121:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, unsigned int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]

   inline void add(const char* unit, const unsigned int value) {

               ^

Multiple libraries were found for "WiFi.h"
 Used: C:\Users\Marco\Documents\Arduino\libraries\WiFi
C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:121:15: note:   no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const char*'

 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:136:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, long int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]

   inline void add(const char* unit, const long value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:136:15: note:   no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const char*'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:151:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, long unsigned int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]

   inline void add(const char* unit, const unsigned long value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:151:15: note:   no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const char*'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:190:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, float) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]

   inline void add(const char* unit, const float value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:190:15: note:   no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const char*'

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:201:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, double) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]

   inline void add(const char* unit, const double value) {

               ^

C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTClient/../CayenneUtils/CayenneDataArray.h:201:15: note:   no known conversion for argument 1 from 'const __FlashStringHelper*' to 'const char*'

Using library CayenneMQTT at version 1.0.1 in folder: C:\Users\Marco\Documents\Arduino\libraries\CayenneMQTT 
Using library WiFi at version 1.2.6 in folder: C:\Users\Marco\Documents\Arduino\libraries\WiFi 
Using library SPI at version 1.0 in folder: C:\Users\Marco\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\SPI 
exit status 1
Error compiling for board WeMos D1 R2 & mini.

Is this the right example for this tis combination?


#3

Well I guess not…:wink:

So, my question now: is there a example code for the Sharp dust sensor and Wemos D1 mini combination?

Thank you!


#4

you need to use this connection example code https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/feature/gsm-support/examples/Connections/ESP8266/ESP8266.ino and add the code of Sharp GP2Y1010AU0F into it.


#5

Best wishes for 2019 shramik and thanks for the support.

I can upload the code to my device but the serial monitor gives:

[7262] Connecting to mqtt.mydevices.com:1883
[14156] Network connect failed
[21231] Network connect failed
[29405] Network connect failed
[36580] Network connect failed
[44654] Network connect failed

My first thought was check the router but I can’t see that it’s blocking port 1883?


#6

Happy new year @marco_rudolph

possibility is some network firewall is blocking traffic to mqtt.mydevices.com or port 1883.


#7

Yes, although I have not found it yet, it has to be something in my router. If set my mobile as an AP I get a connect immediately according to the serial monitor.
In Cayenne I do not yet see a widget but still the message:
Waiting for board to connect …


#8

add #define CAYENNE_DEBUG in your code and share the serial monitor output here.


#9
[8053] Publish: topic 1, channel 0, value 8053, subkey , key 
[8193] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[9325] Publish: topic 1, channel 0, value 9325, subkey , key 
[9482] Publish: topic 1, channel 1, value -96.099, subkey mg, key pm
[10616] Publish: topic 1, channel 0, value 10616, subkey , key 
[10764] Publish: topic 1, channel 1, value -96.099, subkey mg, key pm
[11897] Publish: topic 1, channel 0, value 11897, subkey , key 
[12046] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[13177] Publish: topic 1, channel 0, value 13177, subkey , key 
[13349] Publish: topic 1, channel 1, value -96.099, subkey mg, key pm
[14541] Publish: topic 1, channel 0, value 14541, subkey , key 
[14736] Publish: topic 1, channel 1, value -96.099, subkey mg, key pm
[15908] Publish: topic 1, channel 0, value 15908, subkey , key 
[16056] Publish: topic 1, channel 1, value -96.099, subkey mg, key pm
[17312] Publish: topic 1, channel 0, value 17311, subkey , key 
[17530] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[18728] Connection ok
[18728] Publish: topic 1, channel 0, value 18728, subkey , key 
[19676] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[20816] Publish: topic 1, channel 0, value 20816, subkey , key 
[20974] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[22106] Publish: topic 1, channel 0, value 22106, subkey , key 
[22257] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[23390] Publish: topic 1, channel 0, value 23389, subkey , key 
[23533] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[24665] Publish: topic 1, channel 0, value 24665, subkey , key 
[24818] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[25945] Publish: topic 1, channel 0, value 25945, subkey , key 
[26097] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[27227] Publish: topic 1, channel 0, value 27227, subkey , key 
[27378] Publish: topic 1, channel 1, value -96.879, subkey mg, key pm
[28506] Publish: topic 1, channel 0, value 28505, subkey , key 
[28716] Publish: topic 1, channel 1, value -94.538, subkey mg, key pm
[29921] Connection ok

#10

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

I’m a bit further. I have removed this section above and now you can see the widget :grin:… now find out why I get a negative value

Here is my code:

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

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

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

unsigned long lastMillis = 0;

int measuringPin = A0;
int ledPin = 2;
const int timeMeasuring = 280;
const int timeStabilization = 40;
const int timeSleep = 9680;
float voltageAnalog = 0;
float voltageConversion = 0;
float dustiness = 0;

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

void loop() {
  Cayenne.loop();
     digitalWrite(ledPin,LOW);
    delayMicroseconds(timeMeasuring);
    voltageAnalog = analogRead(measuringPin);
    delayMicroseconds(timeStabilization);
    digitalWrite(ledPin,HIGH);
    delayMicroseconds(timeSleep);
    voltageConversion = voltageAnalog * (4.7 / 1024.0);  //Voltage on 5V pin on Arduino, My voltage is 4.7 V
    dustiness = (0.17 * voltageConversion - 0.1)*1000;
    Cayenne.virtualWrite(1, dustiness, "pm", "mg");
}

#11

you need to come a bit back, as you will hit the rate limit. Have a look at this topic Sending MQTT messages within rate limits

follow this tutorial and first get the correct reading from the sensor http://www.esp8266learning.com/wemos-dust-sensor-example.php


#12

@shramik_salgaonkar, that’s it!

I’ve modified the code and widgets and now I see the values according to the Sharp GP2Y1010AU0F Dust density chart in my dashboard.

Here is the final code for the Sharp GP2Y1010AU0F with Wemos D1 MIni and CayenneMQtt:

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

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

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "*************";   //Cayenne MQTT Username
char password[] = "*************";   // Cayenne MQTT PassWord
char clientID[] = "*************";      // Client ID 

unsigned long lastMillis = 0;

int measuringPin = A0;
int ledPin = D2;

float voltsMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

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

void loop()
{
  Cayenne.loop();

  //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 5000)
  {
    lastMillis = millis();
    
    digitalWrite(ledPin, LOW);
    delayMicroseconds(280);

    voltsMeasured = analogRead(measuringPin);

    delayMicroseconds(40);
    digitalWrite(ledPin, HIGH);
    delayMicroseconds(9680);

    calcVoltage = voltsMeasured * (4.7 / 1024.0); //Voltage on 5V pin on Arduino, My voltage is 4.7 V
    dustDensity = (0.17 * calcVoltage - 0.1);
    Cayenne.virtualWrite(0,calcVoltage, "V");
    Cayenne.virtualWrite(1, dustDensity, "mg");
  
  }
}

No Smoke

Full Smoke

Thanks for that push in the right direction :grinning:


#13

Glad to hear to hear it is working and thanks for sharing the code.