IOT of thing Test aplication

Dear all.

I would like to test below code . I downloaded code from below link. I am arduino version 1.0.1

http://lelylan.github.io/lab-projects/arduino-ethernet-light/

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>


/* ------------------ */
/* SKETCH CREDENTIALS */
/* ------------------ */

char* deviceId     = "<DEVICE-ID>";             // * set your device id (will be the MQTT client username)
char* deviceSecret = "<DEVICE-SECRET>";         // * set your device secret (will be the MQTT client password)
char* outTopic     = "devices/<DEVICE-ID>/set"; // * MQTT channel where physical updates are published
char* inTopic      = "devices/<DEVICE-ID>/get"; // * MQTT channel where lelylan updates are received
char* clientId     = "<CLIENT-ID>";             // * set a random string (max 23 chars, will be the MQTT client id)


/* ------------ */
/* SKETCH LOGIC */
/* ------------ */

/* Server settings */
byte server[] = { 178, 62, 108, 47 }; // MQTT server address

/* Sample payload published to lelylan */
/* The id is the status property id of the basic light /*
/* http://lelylan.github.io/types-dashboard-ng/#/types/518be107ef539711af000001/ */ 
char* payloadOn  = "{\"properties\":[{\"id\":\"518be5a700045e1521000001\",\"value\":\"on\"}]}";
char* payloadOff = "{\"properties\":[{\"id\":\"518be5a700045e1521000001\",\"value\":\"off\"}]}";

/* Ethernet configuration */
byte mac[] = { 0xA0, 0xA0, 0xBA, 0xAC, 0xAE, 0x12 };
EthernetClient ethClient;

/* MQTT communication */
void callback(char* topic, byte* payload, unsigned int length); // subscription callback
PubSubClient client(server, 1883, callback, ethClient);         // mqtt client

/* Pins configuration */
int inPin = 2; // button
int outPin = 4; // led

/* Button and led logics */
int state = HIGH;     // current state of the output pin
int reading;          // current reading from the input pin
int previous = LOW;   // previous reading from the input pin
long time = 0;        // the last time the output pin was toggled
long debounce = 200;  // the debounce time, increase if the output flickers

/* arduino setup */
void setup() {
  Serial.begin(9600);
  delay(500);

  Ethernet.begin(mac);
  Serial.print("Connected with IP: ");
  Serial.println(Ethernet.localIP());

  lelylanConnection();      // MQTT server connection
  pinMode(inPin, INPUT);    // button pin setup
  pinMode(outPin, OUTPUT);  // led pin setup
}

/* arduino loop */
void loop() {
  lelylanConnection();

  char* value;
  reading = digitalRead(inPin);  // read the button state

  // if the input just went from LOW and HIGH and we've waited long enough to ignore
  // any noise on the circuit, toggle the output pin and remember the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == LOW) {
      Serial.println("[PHYSICAL] Led turned on");
      lelylanPublish("on");
      state = HIGH;
    } else {
      Serial.println("[PHYSICAL] Led turned off");
      lelylanPublish("off");
      state = LOW;
    }

    time = millis();
  }

  // effectively update the light status
  digitalWrite(outPin, state);
  previous = reading;
}

/* MQTT server connection */
void lelylanConnection() {
  // add reconnection logics
  if (!client.connected()) {
    // connection to MQTT server
    if (client.connect(clientId, deviceId, deviceSecret)) {
      Serial.println("[PHYSICAL] Successfully connected with MQTT");
      lelylanSubscribe(); // topic subscription
    }
  }
  client.loop();
}

/* MQTT publish */
void lelylanPublish(char* value) {
  if (value == "on")
    client.publish(outTopic, payloadOn); // light on
  else
    client.publish(outTopic, payloadOff); // light off
}

/* MQTT subscribe */
void lelylanSubscribe() {
  client.subscribe(inTopic);
}

/* Receive Lelylan message and confirm the physical change */
void callback(char* topic, byte* payload, unsigned int length) {
  // copu the payload content into a char*
  char* json;
  json = (char*) malloc(length + 1);
  memcpy(json, payload, length);
  json[length] = '\0';

  // update the physical status and confirm the executed update
  if (String(payloadOn) == String(json)) {
    Serial.println("[LELYLAN] Led turned on");
    lelylanPublish("on");
    state = HIGH;
  } else {
    Serial.println("[LELYLAN] Led turned off");
    lelylanPublish("off");
    state = LOW;
  }

  digitalWrite(outPin, state);
  free(json);
}

Error I am getting.

sketch_mar08a:36: error: ‘PubSubClient’ does not name a type
sketch_mar08a.cpp: In function ‘void lelylanConnection()’:
sketch_mar08a:94: error: ‘client’ was not declared in this scope
sketch_mar08a:101: error: ‘client’ was not declared in this scope
sketch_mar08a.cpp: In function ‘void lelylanPublish(char*)’:
sketch_mar08a:107: error: ‘client’ was not declared in this scope
sketch_mar08a:109: error: ‘client’ was not declared in this scope
sketch_mar08a.cpp: In function ‘void lelylanSubscribe()’:
sketch_mar08a:114: error: ‘client’ was not declared in this scope

Where i need to set Default gateway address inorder to provide access??

How to resolve above errors??

PubSubClient.zip (34.9 KB)

Where i need to set Default gateway address inorder to provide access??

Don't worry about that until the code compiles.

How to resolve above errors??

Download and install the library that you clearly failed to download and install.

I downloaded the library compiled successfully on arduino 1.6.6

But i get error has below with compile

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:10:22: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

char* deviceId = “<56debb6351d9d4e74e000015>”; // * set your device id (will be the MQTT client username)

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:11:22: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

char* deviceSecret = “<Y4h+R1NRAxrhFciRhtHLj66ERSv8RExu>”; // * set your device secret (will be the MQTT client password)

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:12:22: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

char* outTopic = “devices//set”; // * MQTT channel where physical updates are published

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:13:22: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

char* inTopic = “devices//get”; // * MQTT channel where lelylan updates are received

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:14:22: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

char* clientId = “”; // * set a random string (max 23 chars, will be the MQTT client id)

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:27:20: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

char* payloadOn = “{“properties”:[{“id”:“518be5a700045e1521000001”,“value”:“on”}]}”;

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:28:20: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

char* payloadOff = “{“properties”:[{“id”:“518be5a700045e1521000001”,“value”:“off”}]}”;

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino: In function ‘void loop()’:

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:75:26: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

lelylanPublish(“on”);

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:79:27: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

lelylanPublish(“off”);

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino: In function ‘void callback(char*, byte*, unsigned int)’:

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:128:24: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

lelylanPublish(“on”);

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:132:25: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

lelylanPublish(“off”);

^

Sketch uses 19,892 bytes (61%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,136 bytes (55%) of dynamic memory, leaving 912 bytes for local variables. Maximum is 2,048 bytes.

char* deviceId = “<56debb6351d9d4e74e000015>”; // * set your device id (will be the MQTT client username)
char* deviceSecret = “<Y4h+R1NRAxrhFciRhtHLj66ERSv8RExu>”; // * set your device secret (will be the MQTT client password)
char* outTopic = “devices//set”; // * MQTT channel where physical updates are published
char* inTopic = “devices//get”; // * MQTT channel where lelylan updates are received
char* clientId = “”; // * set a random string (max 23 chars, will be the MQTT client id)

For this i have attached login details as below.

But i get error has below with compile

I don't see an error.

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:10:22: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

char* deviceId = “<56debb6351d9d4e74e000015>”; // * set your device id (will be the MQTT client username)

In that statement, “<56debb6351d9d4e74e000015>” is a string constant. If you are to define the proper variable to hold it, the variable’s type would be const char *, not char *.

If the warning bothers you, the line should read:

  const char *deviceId = "<56debb6351d9d4e74e000015>";

My question How can i Assign

char* deviceId     = "<DEVICE-ID>";      // * set your device id (will be the MQTT client username)
char* deviceSecret = "<DEVICE-SECRET>";  // * set your device secret (will be the MQTT client password)

My ID =56debb6351d9d4e74e000015
secret=Y4h+R1NRAxrhFciRhtHLj66ERSv8RExu

Mentioned that:
Lelylan uses MQTT, a publish subscribe protocol for the Internet of Things. To make Lelylan communicate with Arduino you need to set two topics: one receiving messages from Lelylan (inTopic) and one sending messages to Lelylan (outTopic). These topics are unique and identified by the device id.

char* outTopic = "devices/<DEVICE-ID>/set"; // * MQTT channel where physical updates are published
char* inTopic = "devices/<DEVICE-ID>/get"; // * MQTT channel where lelylan updates are received

I have warning as below in atached image

const char *deviceId = "56debb6351d9d4e74e000015";
const char *outTopic = "devices/56debb6351d9d4e74e000015/set";
char *deviceId     = "D56debb6351d9d4e74e000015";             // * set your device id (will be the MQTT client username)
char *deviceSecret = "Y4h+R1NRAxrhFciRhtHLj66ERSv8RExu";         // * set your device secret (will be the MQTT client password)
char *outTopic     = "devices/<DEVICE-ID>/set"; // * MQTT channel where physical updates are published
char *inTopic      = "devices/<DEVICE-ID>/get"; // * MQTT channel where lelylan updates are received
char *clientId     = "<CLIENT-ID>";             // * set a random string (max 23 chars, will be the MQTT client id)

I have modified as follow you suggested . Still same error coming

AMPS-N:

char *deviceId     = "D56debb6351d9d4e74e000015";             // * set your device id (will be the MQTT client username)

char *deviceSecret = “Y4h+R1NRAxrhFciRhtHLj66ERSv8RExu”;        // * set your device secret (will be the MQTT client password)
char *outTopic    = “devices//set”; // * MQTT channel where physical updates are published
char *inTopic      = “devices//get”; // * MQTT channel where lelylan updates are received
char *clientId    = “”;            // * set a random string (max 23 chars, will be the MQTT client id)




I have modified as follow you suggested . Still same error coming

Same code - same error warning.
No surprise there.
Read PaulS’ earlier reply.

Yes the error resolved.

void loop() {
  lelylanConnection();

 const char *value;
  reading = digitalRead(inPin);  // read the button state

  // if the input just went from LOW and HIGH and we've waited long enough to ignore
  // any noise on the circuit, toggle the output pin and remember the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == LOW) {
      Serial.println("[PHYSICAL] Led turned on");
      lelylanPublish("on");
      state = HIGH;
    } else {
      Serial.println("[PHYSICAL] Led turned off");
      lelylanPublish("off");
      state = LOW;
    }

    time = millis();
  }

  // effectively update the light status
  digitalWrite(outPin, state);
  previous = reading;
}

/* MQTT server connection */
void lelylanConnection() {
  // add reconnection logics
  if (!client.connected()) {
    // connection to MQTT server
    if (client.connect(clientId, deviceId, deviceSecret)) {
      Serial.println("[PHYSICAL] Successfully connected with MQTT");
      lelylanSubscribe(); // topic subscription
    }
  }
  client.loop();
}

/* MQTT publish */
void lelylanPublish(char* value) {
  if (value == "on")
    client.publish(outTopic, payloadOn); // light on
  else
    client.publish(outTopic, payloadOff); // light off
}

/* MQTT subscribe */
void lelylanSubscribe() {
  client.subscribe(inTopic);
}

/* Receive Lelylan message and confirm the physical change */
void callback(char* topic, byte* payload, unsigned int length) {
  // copu the payload content into a char*
 const char *json;
  json = (char*) malloc(length + 1);
  memcpy(json, payload, length);
  json[length] = '\0';

  // update the physical status and confirm the executed update
  if (String(payloadOn) == String(json)) {
    Serial.println("[LELYLAN] Led turned on");
    lelylanPublish("on");
    state = HIGH;
  } else {
    Serial.println("[LELYLAN] Led turned off");
    lelylanPublish("off");
    state = LOW;
  }

  digitalWrite(outPin, state);
  free(json);
}

For this part its showing

Arduino: 1.6.6 (Windows 8.1), Board: "Arduino/Genuino Uno"

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino: In function 'void loop()':

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:77:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lelylanPublish("on");

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:81:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lelylanPublish("off");

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino: In function 'void callback(char*, byte*, unsigned int)':

IOT_Testcode:124: error: invalid conversion from 'const void*' to 'void*' [-fpermissive]

memcpy(json, payload, length);

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:25:0,

from sketch\IOT_Testcode.ino.cpp:1:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\string.h:117:14: error: initializing argument 1 of 'void* memcpy(void*, const void*, size_t)' [-fpermissive]

extern void *memcpy(void *, const void *, size_t);

^

IOT_Testcode:125: error: assignment of read-only location '*(json + ((sizetype)length))'

json[length] = '\0';

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:130:24: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lelylanPublish("on");

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:134:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lelylanPublish("off");

^

IOT_Testcode:139: error: invalid conversion from 'const void*' to 'void*' [-fpermissive]

free(json);

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:23:0,

from sketch\IOT_Testcode.ino.cpp:1:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:305:13: error: initializing argument 1 of 'void free(void*)' [-fpermissive]

extern void free(void *__ptr);

^

exit status 1
invalid conversion from 'const void*' to 'void*' [-fpermissive]

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

You have been told what to do to make the warnings go away. Engage your fingers in the IDE or external text editor for a while, not here.

Arduino: 1.6.6 (Windows 8.1), Board: "Arduino/Genuino Uno"

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino: In function 'void loop()':

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:77:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lelylanPublish("on");

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:81:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lelylanPublish("off");

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino: In function 'void callback(char*, byte*, unsigned int)':

IOT_Testcode:124: error: invalid conversion from 'const void*' to 'void*' [-fpermissive]

memcpy(json, payload, length);

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:25:0,

from sketch\IOT_Testcode.ino.cpp:1:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\string.h:117:14: error: initializing argument 1 of 'void* memcpy(void*, const void*, size_t)' [-fpermissive]

extern void *memcpy(void *, const void *, size_t);

^

IOT_Testcode:125: error: assignment of read-only location '*(json + ((sizetype)length))'

json[length] = "\0";

^

IOT_Testcode:125: error: invalid conversion from 'const char*' to 'char' [-fpermissive]

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:130:24: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lelylanPublish("on");

^

C:\Users\Ajit\Desktop\IOT_Testcode\IOT_Testcode.ino:134:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

lelylanPublish("off");

^

IOT_Testcode:139: error: invalid conversion from 'const void*' to 'void*' [-fpermissive]

free(json);

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:23:0,

from sketch\IOT_Testcode.ino.cpp:1:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:305:13: error: initializing argument 1 of 'void free(void*)' [-fpermissive]

extern void free(void *__ptr);

^

exit status 1
invalid conversion from 'const void*' to 'void*' [-fpermissive]

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

I could not able to resolve the warning message. I have changed as per suggestion. Still i am getting these warning.

Loop code as below

void loop() {
  lelylanConnection();

 const char *value;
  reading = digitalRead(inPin);  // read the button state

  // if the input just went from LOW and HIGH and we've waited long enough to ignore
  // any noise on the circuit, toggle the output pin and remember the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == LOW) {
      Serial.println("[PHYSICAL] Led turned on");
      lelylanPublish("on");
      state = HIGH;
    } else {
      Serial.println("[PHYSICAL] Led turned off");
      lelylanPublish("off");
      state = LOW;
    }

    time = millis();
  }

  // effectively update the light status
  digitalWrite(outPin, state);
  previous = reading;
}

/* MQTT server connection */
void lelylanConnection() {
  // add reconnection logics
  if (!client.connected()) {
    // connection to MQTT server
    if (client.connect(clientId, deviceId, deviceSecret)) {
      Serial.println("[PHYSICAL] Successfully connected with MQTT");
      lelylanSubscribe(); // topic subscription
    }
  }
  client.loop();
}

/* MQTT publish */
void lelylanPublish(char *value) {
  if (value == "on")
    client.publish(outTopic, payloadOn); // light on
  else
    client.publish(outTopic, payloadOff); // light off
}

/* MQTT subscribe */
void lelylanSubscribe() {
  client.subscribe(inTopic);
}

/* Receive Lelylan message and confirm the physical change */
void callback(char *topic, byte* payload, unsigned int length) {
  // copu the payload content into a char*
 const char *json;
  json = (char *) malloc(length + 1);
  memcpy(json, payload, length);
  json[length] = "\0";

  // update the physical status and confirm the executed update
  if (String(payloadOn) == String(json)) {
    Serial.println("[LELYLAN] Led turned on");
    lelylanPublish("on");
    state = HIGH;
  } else {
    Serial.println("[LELYLAN] Led turned off");
    lelylanPublish("off");
    state = LOW;
  }

  digitalWrite(outPin, state);
  free(json);
}
      lelylanPublish("on");

Clearly, this function expects a char *. You are passing it a const char *.

FIX THE FUNCTION DEFINITION TO EXPECT A const char *!