ESP8266 Xap and Alexa

13 replies [Last post]
brett
Offline
Providence, United States
Joined: 9 Jan 2010

I have been messing around with the ESP8266 and have built an xAP library framework for it.
One of the demo's  posted is for simultaneous Alexa and xAP control check out xapDemo4.ino

https://github.com/dbzoo/esp8266-xap

xapDemo4 - Alexa/Xap demo video https://photos.app.goo.gl/0cGw7Hnf8Qec6Qm83

I'm using a sonoff dev board with a few electronic bricks for quick prototyping:

https://www.itead.cc/sonoff-dev.html

Brett

kim
Offline
Throwleigh, United Kingdom
Joined: 1 Dec 2010
Very interesting...

.... because 1) I have been given an Alexa for Xmas 2) Xively have announced they are closing down their personal sites in mid Jan 2018.  I emailed them about commercial rates and they said "tens of thousands"! 

I need to look elsewhere - and work out how to do it.  Any recommendations?

Up until now I have been using Wemos D1 minis quite a lot (up to 6 so far in various places) and AdaFruit io - however they only allow 10 feeds and I have 16 from two of your liveboxes alone!

The idea of having a wemos sitting on the network picking up the xap packets and publishing them somewhere is attractive - especially if I can then find a way of interrogating the data with an Alexa skill.  Lots of steps there I know.

So I shall start off trying one of your demos and seeing if I can get it to be an xfx message viewer.

Attached is one of my "programs" (uploaded as a txt file 'cos it won't accept .ino) - I can't really program in C but seem to be able to hack other peoples a bit.  This has quite a nice WIFI manager which avoids hard coding wifi credentials.  Great when I have to move the device to someone else's network (the village hall archive in this case).  Also I had to make use of deepsleep - stopping everything for five minutes - otherwise the temperature picked up the heat of the esp8266 and overread and the humidity under-read.  Letting it all cool down in deep sleep seemed to sort it.

Don't laugh at my programming please!

Happy new year

Kim 

AttachmentSize
kimwodemo.txt 5.18 KB
kim
Offline
Throwleigh, United Kingdom
Joined: 1 Dec 2010
oops...

.... didn't read the other recent posts.  Am I to assume that Graphite using some sort of Cloud resource is the preferred answer now?

kim
Offline
Throwleigh, United Kingdom
Joined: 1 Dec 2010
Success

After normal faffing around with dependent libraries I got all four demos working.  Yay!

Points:  1) In the button demo 2, the lamps did not do anything on xfx viewer - even though I got button pressed messages.  Admittedly I didn't actually wire the leds up.

            2) In Demo4 I got the following error:

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

xapDemo4:64: error: void value not ignored as it ought to be

 

   const unsigned char lampMo1 = fauxmo.addDevice("lamp one"); // device_id 0

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

which without much hope I changed to:

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

fauxmo.addDevice("lamp one");

const unsigned char lampMo1 = 0;

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

this is using Arduino 1.8.3 and may be entirely wrong - except it seems to work :)

Now back to reading all the stuff in HAH about xap/MQTT - so far I can only find MQTT --> xap (for iserver?) and not the other way around.

Happy New Year!

brett
Offline
Providence, United States
Joined: 9 Jan 2010
I don't understand why you

I don't understand why you got those errors as the fauxmoESP.h file definately defines the addDevice method as returning an unsigned char and not void as your error indicates.   Perhaps you have an older version of the library.

class fauxmoESP {
    public:
        fauxmoESP(unsigned int port = DEFAULT_TCP_BASE_PORT);
        unsigned char addDevice(const char * device_name);
        bool renameDevice(unsigned char id, const char * device_name);
        char * getDeviceName(unsigned char id, char * buffer, size_t len);
        void onMessage(TStateFunction fn) { _callback = fn; }
        void enable(bool enable);
        void handle();

In anycase your workaround is ok as that is the end result you are expecting.
Good that you got it working - It pairs just like a wemo to Alexa

Brett

kim
Offline
Throwleigh, United Kingdom
Joined: 1 Dec 2010
Yup

.... how right you are.  Mine says:

class fauxmoESP {

 

    public:

 

        fauxmoESP(unsigned int port = DEFAULT_TCP_BASE_PORT);

        void addDevice(const char * device_name);

        void onMessage(TStateFunction fn) { _callback = fn; }

        void enable(bool enable) { _enabled = enable; }

        void handle();

Version 2.0.0 Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>

Just shows how my "google and download" is vulnerable.  
brett
Offline
Providence, United States
Joined: 9 Jan 2010
Ah then that was your

Ah then that was your mistake.  You should be using the built-in library manager and asking it to get you the latest src code.
From the Arduino IDE menu : Sketch -> Include Library -> Manage Libraries
Then search for fauxmoesp
The IDE will automatically download and keep this library updated with the latest copy which will be version 2.2.0 (not 2.0.0 as you have)

Brett

kim
Offline
Throwleigh, United Kingdom
Joined: 1 Dec 2010
thanks

It was in there - but not updateable.  Probably because I dumped the unzipped into the libraries folder rather than using the manager.

Got v 2.3.0 in there now.  Thanks for your help.

Kim 

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Thanks Brett

This is a really nice library. In no time at all I've managed to knock up an ESP8266 node running an input from my smoke alarm, 1wire temp and acting as a URF transmitter. Excellent stuff, many thanks for your efforts! 

one thing I did notice, the classes are reporting as info and event and not xAPBSC.info, etc

traced this down to the following line in Bsc.cpp

BscInfoEvent::Info ? "info" : "event";

Changed it in my version of library and all good now 

 

thanks again

Garry

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Gary right you are.  How did

Gary right you are.  How did I miss that.   I've commited the change as you suggested.  Thanks!
Glad you like the library and find it easy to work with.

Brett

vincent
Offline
Joined: 31 Aug 2014
cant compile now

Hello

for a while I come back to this project but the lib have evolved, I have a compilation error while trying to create new devices for my installation. an idea ?

Les options de compilation ont été modifiées, tout sera recompilé

C:\Users\vincent\Documents\Arduino\libraries\xap\xap.cpp: In lambda function:

C:\Users\vincent\Documents\Arduino\libraries\xap\xap.cpp:21:20: error: ambiguous overload for 'operator~' (operand type is 'IPAddress')

     _broadcastIP = ~WiFi.subnetMask() | WiFi.gatewayIP();

                    ^

C:\Users\vincent\Documents\Arduino\libraries\xap\xap.cpp:21:20: note: candidates are:

C:\Users\vincent\Documents\Arduino\libraries\xap\xap.cpp:21:20: note: operator~(uint32_t {aka unsigned int}) <built-in>

C:\Users\vincent\Documents\Arduino\libraries\xap\xap.cpp:21:20: note: operator~(u32_t {aka long unsigned int}) <built-in>

C:\Users\vincent\Documents\Arduino\libraries\xap\xap.cpp:21:20: note: operator~(int) <built-in>

exit status 1

Erreur de compilation pour la carte WeMos D1 R1

brett
Offline
Providence, United States
Joined: 9 Jan 2010
I only just got back from a

I only just got back from a week away from my computer.  Let me look into that compilation issue.  It is odd as I built several demo programs with library and I didn't have any error.   Perhaps something changes in the compiler or the ESP development environment.  As I don't have the original dev. environment available I'll have to stand up a new one to check out my code.

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Indeed something had changed

Indeed something had changed in the library that broken the XAP library.  I've corrected that line and pushed it to github.

https://github.com/dbzoo/esp8266-xap/commit/b215e827ef021b5476e2aa79e40202102e1eba0f

vincent
Offline
Joined: 31 Aug 2014
thanks

hello, i had corrected in my arduino ide, i am at work with sonoff products, long life to xap

Hardware Info