Arduinp +shield does not connect

65 views
Skip to first unread message

emiy...@gmail.com

unread,
Feb 4, 2015, 10:23:08 AM2/4/15
to lel...@googlegroups.com
Am i doing something wrong here ?

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
 
 
/* ------------------ */
/* SKETCH CREDENTIALS */
/* ------------------ */
 
char* deviceId = "54.......................00005b"; // * set your device id (will be the MQTT client username)
char* deviceSecret = "Y.........................m1Xn"; // * set your device secret (will be the MQTT client password)
char* outTopic = "devices/54....................00005b/set"; // * MQTT channel where physical updates are published
char* inTopic = "devices/54...............00005b/get"; // * MQTT channel where lelylan updates are received
char* clientId = "c1"; // * 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, 0xA0, 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()) {
   Serial.println("[PHYSICAL] connected with MQTT ?");
// connection to MQTT server
if (client.connect(clientId, deviceId, deviceSecret)) {
Serial.println("[PHYSICAL] Successfully connected with MQTT");
lelylanSubscribe(); // topic subscription
}
else
{
Serial.println("[PHYSICAL] Not 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);
}

serial monitor

Connected with IP: 192.168.1.144
[PHYSICAL] connected with MQTT ?
[PHYSICAL] Not connected with MQTT
[PHYSICAL] connected with MQTT ?

emiy...@gmail.com

unread,
Feb 4, 2015, 7:46:17 PM2/4/15
to lel...@googlegroups.com, emiy...@gmail.com

the edits i made are only in the * MQTT server connection (i added 2 serial prints to see if something is mooving there) ...  and the SKETCH CREDENTIALS .

Lelylan Touch

unread,
Feb 5, 2015, 8:52:44 AM2/5/15
to lel...@googlegroups.com, emiy...@gmail.com
That's really strange. We're digging on it and try to find out what's the problem.

On 5 February 2015 at 01:46, <emiy...@gmail.com> wrote:

the edits i made are only in the * MQTT server connection (i added 2 serial prints to see if something is mooving there) ...  and the SKETCH CREDENTIALS .

--
You received this message because you are subscribed to the Google Groups "Lelylan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lelylan+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Andrea Reginato
Lelylan, Building the Connected Home
http://lelylan.com

Lelylan Touch

unread,
Feb 6, 2015, 5:47:01 AM2/6/15
to lel...@googlegroups.com, bxtrem
Hi Emiy, 

we fixed some problems we had with the MQTT server and everything should be now up and running. Could you try right now to upload the sketch telling us if everything is working out? Thanks a lot for your time and let us know!

emiy...@gmail.com

unread,
Feb 7, 2015, 7:54:03 AM2/7/15
to lel...@googlegroups.com, emiy...@gmail.com
Hi  .
I tested again ant stil no conection  ..
I am using internet from the university .. and there are many ports clised  .. it might this be the problem ?
Tested few dais ago other services that used mqtt on other servers with the same arduino+ shield and worked

Lelylan Touch

unread,
Feb 7, 2015, 12:36:23 PM2/7/15
to lel...@googlegroups.com, bxtrem
Hi Emiy, 

Our test devices with Arduino are working fine and the MQTT server is up and running. I'm starting to think about the Ethernet Shield (which we never used) as the possible problem. To better understand what is wrong, could you give us your client ID? This way we can debug and search for additional debug info.

Sincerely,

emiy...@gmail.com

unread,
Feb 8, 2015, 5:09:08 AM2/8/15
to lel...@googlegroups.com, emiy...@gmail.com

The specific client id in the arduino code ? ... this is something that a tought about .. that  since i have to imput a random id just in the arduino code .. and not at all in the web platform

i am loging with my mail emiy_...@yahoo.com

char* deviceId = "54d2323b63e36e49a200005b"; // * set your device id (will be the MQTT client username)
char* deviceSecret = "Y1AzvjI8W9Nl9oH3cOA0YT8y0mD3m1Xn"; // * set your device secret (will be the MQTT client password)

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

Another ting that i am thinking is the arduino ethernet library
i am using th new one with dhcp and dns suport that is included in the 1.0.6 of arduino ide

thedean...@gmail.com

unread,
Mar 5, 2015, 8:26:13 AM3/5/15
to lel...@googlegroups.com, emiy...@gmail.com
Hi I'm trying Lelylan for the first time and it seems I'm experiencing the same problem as Emiy.

Using the serial monitor I only get as far as:
Connected with IP: 192.168.1.240
So it doesn't appear to be connecting successfully with the MQTT server.

I'm using an Arduino Uno  with a Hanrun ethernet shield. Shield has been used successfully for other projects, and I've just tested using a webserver sketch, all good.

Thanks in advance,

Dean

Lelylan Touch

unread,
Mar 5, 2015, 2:01:17 PM3/5/15
to lel...@googlegroups.com, bxtrem
@emiy - We made some test and everything should be fine. I'm not sure about the cause, but as far as we can't use the exact arduino ethernet shield we're unable to solve the problem. And right now, we don't have it. I'll open an issue, trying to figure it out what's wrong.

@dean. We're fixing some bugs on our MQTT server. Could you try it now and let us know if things are working out? If the problem persist, most probably there is something missing between the ethernet and out MQTT implementation (wich is based on open source software who should respect the MQTT protocol). 

Thanks to both of you and let us know.

Dean Wilson

unread,
Mar 5, 2015, 2:14:29 PM3/5/15
to lel...@googlegroups.com
Thanks for the reply,

I won't be able to test this until next week now. Will update you when I do.

Regards

Dean



--
You received this message because you are subscribed to a topic in the Google Groups "Lelylan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lelylan/5F55HTXmg8Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lelylan+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
DW

----------------------------------------------------------------------------------------------------------------------------------------
"really we are just a whole lot of nothing with a bit of everything thrown in for goodmeasure"
Christopher Manson esq. President, Newcastle Institute of Pataphysics

----------------------------------------------------------------------------------------------------------------------------------------

Dean Wilson

unread,
Mar 11, 2015, 5:57:58 AM3/11/15
to lel...@googlegroups.com
Hi,

Managed to try out the Arduino again yesterday, but still no joy. 

Have carried out the electric imp example with no problems - works like a dream :-) Arduino on the otherhand seems to be unable to communicate with the MQTT server and the physical on/off is not working as it should.

I also have problems trying to access the dashboard on my iPhone. I don't seem to be able to get past the sign-in screen for some reason. Any ideas?

Cheers

Dean

Lelylan Touch

unread,
Mar 11, 2015, 10:00:35 AM3/11/15
to lel...@googlegroups.com
The dashboard problem is related to a known bug. It's in the TODO list and we hope to fix it soon. 

About MQTT, I would love to ask you one more trial. We're monitoring our logs and if you give us your device ID we'll check it out trying to find the potential problem.

Let us know.

thedean...@gmail.com

unread,
Mar 13, 2015, 6:04:44 AM3/13/15
to lel...@googlegroups.com
Hi, thanks for the support.

My device Id is 54ff69338ef1bc7078000068

I'm also having trouble with creating a webapp. I've tried multiple times now, following the instructions to the letter, but keep hitting a wall when trying to preview the app using the serve command. 

Cheers

Dean

Lelylan Touch

unread,
Mar 13, 2015, 6:52:06 AM3/13/15
to lel...@googlegroups.com
Hi Dean, 

the app behaviour looks strange. We've make it during a conference lately and it was working straight. 

I leave you with this link showing in more detailed way how to set a Web App using the device directive. 
Following these instructions, could be of help.

Few questions. Which version of node are you running? Which errors come out when firing the server?
Today we're checking for the logs.

Lelylan Touch

unread,
Mar 13, 2015, 10:43:06 AM3/13/15
to lel...@googlegroups.com
Hi Dean, 

we checked out the MQTT logs but we couldn't find your device ID. 

It looks like your ethernet shield wasn't even able to start the connection phase with our servers (where we can see if a connection was a positive or a negative one). As we are trying to open an issue for every shield/hardware not working, could you please let us know which is your hardware?

Thanks a lot.

On 13 March 2015 at 11:04, <thedean...@gmail.com> wrote:

Andrea Reginato

unread,
Mar 13, 2015, 10:59:52 AM3/13/15
to lel...@googlegroups.com, thedean...@gmail.com
Hi Dean, 

if your problem is related to the impossibility of running the serve command, that could be due to the missing of grunt.
If you do npm install grunt -g everything should work just fine.

Best.

Dean Wilson

unread,
Mar 20, 2015, 10:51:27 AM3/20/15
to Andrea Reginato, lel...@googlegroups.com
Hi all, I've still to have another play with getting the Arduino to work and to build the web app. In the meantime I have just published a review of my first attempts at using Lelylan with the Electric Imp. Hope, you like it: http://fluxx.uk.com/2015/03/home-automation-experiment/#.VQwx3WSsU82

Lelylan Touch

unread,
Mar 23, 2015, 7:28:02 AM3/23/15
to lel...@googlegroups.com, Andrea Reginato
Hi Dean, 

I've just read your beautiful article integrating Lelylan with an Electric Imp. I simply love it!
I'm gonna write you separately if you don't mind, exchanging some thoughts.

Best

P.S. Let me know when you'll be able to try out the Ethernet solution.


Dean Wilson

unread,
Mar 23, 2015, 1:34:16 PM3/23/15
to lel...@googlegroups.com
You are too kind! :-)

I've sent you a further response separately. Maybe we could organise a call?
Reply all
Reply to author
Forward
0 new messages