Monthly Archives: April 2016

The Electrodragon Alternative

 

electrodragon[6]Part 1: At $6, the Electrodragon “WIFI IOT Relay Board based on ESP8266” looks like a force to be reckoned with, offering WIFI control over two 10 amp relays. But what about the SONOFF from ITEAD? How do they compare?

Making use of their own incredibly cheap power supply is one reason the cost is so low and the board looks on the surface to be well made and well thought out – but read on.

The unit uses what appears (from the antenna design) to be the ESP-12F module which, it is said, has a better antenna than previous models but is otherwise pretty much like the ESP-12E.

The two relay outputs are on GPIO12 and 13 respectively – with the status LED on GPIO16. The socket for a temperature sensor uses GPIO14 !!! That’s new – usually people use GPIO2. Oh, well.

In order to do the board justice I went off to their website http://www.electrodragon.com/w/ESP_Relay_Board#Pin_Mapping_and_Wiring and there seemed to be a fair bit of info available. Clearly the first thing I’d be interested in would be blowing my own software. The page refers to buttons 0 and 1 but on the board are buttons 1 and 2…  but elsewhere they clarify these as buttons 1 and 2. I had expected these would be used for reset and programming respectively and that as it happens is easy as a 6*2 way connector conveniently brings out RX and TX. In practice one of them does indeed go to GPIO1 for programming but you have to power cycle the board to start programming – that kept me going for a while… always read the manual.

electrodragonThe case of the module I received, it would seem, was one already available because the 4-way connection bringing out the power via the relays, is partially obscured by the case itself. Not a good idea when you’re messing with mains wires – and especially those able to take 10 amps – but wait - there are lots of thing they’ve gotten right – the neutral line is not only separated from the live by a gap but it is also on the other side of the board, but the two tracks bringing power right across the board from the mains to the two relays –  while being nicely isolated by an air gap which is GOOD, are WAY too thin to handle a total of 20 amps (2 * 10amp relays) or, IMHO. I’m happy with that as I’m only likely to want to power a couple of bulbs but it seems a bit daft to use a pair of 10 amp relays then keep the track so narrow – around 1mm.

The power supply claims to have all matter of things including temperature protection, overcurrent, overvoltage and short circuit full protection, high and low voltage isolation – and yet, it is a really small and simple looking, exceedingly low cost model available for little under £1 – do we believe the claims? Do they matter? If you’re powering only the relays there’s not much chance of getting an electric shock but the board encourages you to attach a DHT22 which means you could be in contact with wires – my only advice here would be never to touch them when this board is connected to the mains – and make sure no-one else can.  But why you ask, surely you’d put the DHT22 in the unit itself?  Not if you want any meaningful temperature sensing out of it – these devices HAVE to have air around them and not the warm air off a power supply. Really, don’t waste your time putting a temperature sensor inside this OR a SONOFF box unless of course you’re using it to see how hot the electronics get.

So, how was I going to test this unit – I noticed something about AT commands – but I gave up on that way of programming with ESP8266 chips a LONG time ago – regular readers will know that I generally talk to such boards by MQTT protocol using my own code as found in the Home Control 2016 project and the prize-winning (subtle) WIFI Touch Display project and this was to give me pause for thought as I use GPIO13 for status indication – as do the SONOFF units and the relays here are on 12 and 13.

Well, nothing should be set in stone so I spent the evening adding more commands to my code and added a function to allow for these Electrodragon units – strangely enough I’ve named the command “electrodragon” – if set to 1… we’re using these boards, if set to 0, we’re not! Simples.

Programming Electrodragon

So, I’d not realised this but reader Nathan tells me that the chip isn’t actually programmed other than what’s on the chip initially i.e. the AT command set. So that has to come off.

Above you see a picture of a typical FTDI – that is the little box that plugs into your PC or whatever and converts USB into serial signals. That box is wired as you see above to the connector on the Electrodragon – and the button I’ve highlighted is the one that needs pressing BEFORE AND DURING POWERON in order to put the Electrodragon into programming mode.

To program the board I did NOT connect it to the mains or to any output. I connected up my FTDI as you see above – now, the sharp reader might say “but that’s on the 5v setting by the link on the FTDI and won’t that break the board?” – I have to say that the vast majority of the information on the web says YES, but here’s why I’ve done it this way: firstly putting the FTDI in 3v3 mode means it has VERY little power to spare and in many cases you’ll end up with relays jittering and lights flashing and you’ll get no-where (that would be with the power (red) lead elsewhere of course – bottom right pin in fact on the Electrodragon), and secondly while I would never normally use 5v logic with an ESP8266, I have NEVER broken an ESP12 by using a 5v FTDI signal on the serial.  Serial from the Electrodragon incidentally to the FDTI is fine – it’s the higher voltage serial output from the FTDI to the serial in on the Electrodragon we’re talking about.  Your choice if you decide to copy me – but specifically using FTDIs that look like the one above – I have blown ESP12s WELL over 1000 times without doing them any harm. The alternative is a 3v3 power supply feed to the board and leave the power output of the FTDI unconnected. Your choice, your responsibility.

Remember I use my own software that needs to talk to MQTT and have access to a WIFI access point.

For the software you need to go to the home control 2016 blog – there is source code for the Windows Unofficial Programming Environment or a pair of ROMS for those unable to do this (and to be fair it took me a while to get to grips with using the SDK etc)  – RBOOT.BIN to 0x000000 and ROMX.BIN to 0x002000 using your preferred tool. The ROMS are in the root of www.scargill.net.  Once programmed, disconnect and reconnect the FTDI.  Most likely you won’t see the light flashing on the board. Instead you’ll hear a relay flashing on and off quickly – that’s because by default, GPIO13 is an indicator!!!!  At 115,200k send serially the commands:

{wifi_button:1}

{electrodragon:1}

The relay will stop clicking but the indicator won’t yet flash - and now reboot – the indicator on the board should start to flash and these commands will now work…  {out13:1}, {out13:0}, {out12:1}, {out12:0} – so that’s your two relays working - you’ll then need to go through the instructions to set up your WIFI access point and MQTT details – that’s done by a web interface or just as easily you can do it by serial just as above. Once that is done – Bob’s your uncle.

So in my case:

{id:”electro2”}

{ssid:”wififorus”}

{pass:”xxxxxxxx”}

{ssid2:”wififorus”}

{pass2:”xxxxxxxx”}

{mqtt_host:”192.168.1.19”}

{mqtt_pass:”xxxxxxxx”}

{mqtt_port:1883}

{mqtt_user:”admin”}

{mqtt_pass:”xxxxxxxx”}

reboot (i.e. pull the power and reconnect.

Now WHY does that have to be complicated by adding a second SSID? Because my software handles two of them for backup and while you’re messing about it is trying to connect to a default SSID you don’t have – there’s a chance by the time you get around to it that it is trying to connect to the SECOND SSID.  If you can’t be bothered to put the second one in – eventually the unit will get around to trying the first one again.

I’m calling my units “electro1” and “electro2” as I have two of them – they are now all programmed up and ready to go. Just to be sure I was not missing anything I left one on at midnight last night and as expected it operated flawlessly.

NEXT: Plug in the power - I don’t expect any surprises. Nathan and I have both passed comment about the power – from here on it is all your responsibility.

Facebooktwittergoogle_pluspinterestlinkedin

Status update

GaleraIt may seem like I’ve been quite the past week – but having arrived safely in Spain we’ve had lots to do.  However I have done some updates to the “home control 2016” blog entry as I’ve implemented some fixes to the node-red-contrib-esplogin node.

For those of you unfamiliar with this – the idea is a node-red node that updates a bunch of ESP8266 modules with time and date info as well as dusk and dawn timings. It does this on power-up of Node-Red, on demand from individual units and every 12 hours – except it wasn’t doing it every 12 hours. It is now. Here’s the link for those interested. The node itself also now has much better status information and help. http://flows.nodered.org/node/node-red-contrib-esplogin

cludgeMeanwhile I’ve been struggling with rubbish broadband back home in England as the router failed every now and then to reconnect. Aidan and I have implemented a solution using one of the ESP8266 modules which will check Google every minute and if it gets nothing for 10 minutes will reboot the router.

new layoutAidan is working on a new version of the home control board with a couple of minor improvements – the connection for a Dallas temperature chip is now a 4-pin job suitable for the Dallas chip or the DHT-22 and we’re also putting on-board an optional RGB serial LED as the status LED on the board uses all sorts of flashing convolutions to indicate state and we thought it might be nice to use colours instead. There  is still a question mark over simultaneously using PWM and sending serial data to LEDs and that is being tested right now.

There’s a significant update to the ESP8266 source(home control 2016 project etc.) as I fixed a minor silly in my watering system code. https://bitbucket.org/scargill/esp-mqtt-dev and added a load of improvements including a serial RGB indicator LED

Meanwhile I’m sitting here on the edge of my seat waiting for a new Nikon camera to arrive so I can make best use of the excellent weather out here in Andalusia.

Facebooktwittergoogle_pluspinterestlinkedin

North East Maker Faire 2016

peepsI could not be there at the Maker Faire UK in the Centre for Life in Newcastle – but thanks to my spies – it’s great to see so many people there.

Apparently this couple on the left are into ESP8266 and got some ideas from the blog.  Glad you like it guys and sorry I could not be there. Understand you had a chat with Aidan.

Hope everyone there is having a great time – let us know if you’re looking in.

Meanwhile I’m in and settled in Spain – spent the whole day updating software (and more to go as in many of my older boards there was no OTA software.  Just cracked the problems I was having with PWM on the ESP software and so the repository now along with the .BIN file I made available are all updated. 

And now, while the sun is shining (and it is 23c outside) I’m off to update the rest of my boards.

Facebooktwittergoogle_pluspinterestlinkedin

PWM Woes

 

Just in case anyone is having issues with the ESP8266 SDK and PWM. Problem now “solved” but you might find this interesting.

For many months now I’ve been using the PWM on the ESP8266 successfully, so much so that I’ve not tested it and just recently I’ve noticed it no longer works. Specifically, the PWM startup routine forces my ESP8266s to reboot with a watchdog timeout.

So first things first, the SDK manual appears to STILL be incorrect. It states in version 1.53 (ESP8266 SDK API guide) in page 178 that the DUTY parameter is pointer to an 8 bit array.

Yet the header and routines elsewhere require 32 bit values for the array. I’ve always ignored this.

#define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTDO_U
#define PWM_1_OUT_IO_NUM 15
#define PWM_1_OUT_IO_FUNC FUNC_GPIO15

#define PWM_3_OUT_IO_MUX PERIPHS_IO_MUX_GPIO4_U
#define PWM_3_OUT_IO_NUM 4
#define PWM_3_OUT_IO_FUNC FUNC_GPIO4

#define PWM_4_OUT_IO_MUX PERIPHS_IO_MUX_GPIO5_U
#define PWM_4_OUT_IO_NUM 5
#define PWM_4_OUT_IO_FUNC FUNC_GPIO5

uint32 duty[] = {0, 0, 0};
uint32 freq = 1000;
static uint8 donepwm = 0;

uint32 io_info[][3] = {
  {PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC, PWM_1_OUT_IO_NUM},
  {PWM_3_OUT_IO_MUX, PWM_3_OUT_IO_FUNC, PWM_3_OUT_IO_NUM},
  {PWM_4_OUT_IO_MUX, PWM_4_OUT_IO_FUNC, PWM_4_OUT_IO_NUM}
};

So with these definitions I call….

if (donepwm == 0) {
   pwm_init(freq, duty, 3, io_info);
   donepwm = 1;
}

 

You should call the setup once only.. hence the wrapper using “donepwm”. This has always worked and yet now, no matter what I do, this crashes the processor – usually a few seconds after it has been called.

Result..

ets Jan  8 2013,rst cause:4, boot mode:(1,0)

wdt reset

This used to work – now it causes the WDT.

The example in the manual..

Example: uint32 io_info[][3] =  {{PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM},          {PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM}, {PWM_2_OUT_IO_MUX,PWM_2_OUT_IO_FUNC,PWM_2_OUT_IO_NUM}};

pwm_init(light_param.pwm_period, light_param.pwm_duty, 3, io_info);

HERE is a  “fix”…

http://www.esp8266.com/viewtopic.php?f=6&t=4675&p=46060#p46060

I amended the rom0.ld file and sure enough – fixed…

But that means there’s an issue somewhere –  and that manual needs fixing  - I hope Espressif are looking in.

Facebooktwittergoogle_pluspinterestlinkedin

Simple Serial Terminal lost blog

For reasons beyond me the original article on my serial terminal, originally put together when I was messing with LUA, has disappeared from the blog entirely – and so here’s a quickly updated version with DropBox link.

Serial Terminal

So above right you should see the editor. The most important bits are the two big windows – on the left is the area you type in – multi line – and on the right is the output from the serial line – i.e. what comes back from the chip. In the simplest case you set up the serial port you want, ensure it’s set to the right baud rate, select “serial – open” and you’re all set (I’m assuming you have an FTDI or similar on your USB lead, talking to the serial on the ESP8266 device. You can send all of that out the serial line – or just a selected area or indeed whatever is in your clipboard. Also you can define up to 10 pages of info (Notepads) and send that – in addition you have up to 9 presets – handy for initialisation sequences. Oh and you can save the left panel into a file if you want.

Whatever you type in the left window is non-volatile, i.e. it’ll still be there after you blow up your serial port and have to reboot the computer.

Disclaimer: if any of the above or the use of the terminal breaks your computer, it’s not my fault. I’m providing this freely just because I’ve no reason not to but without support. You just need the exe file for this… PetesSerialTerminal.EXE and note that Windows XP is not supported.

So let’s take a look at the top first. I have deliberately kept this as clean and simple looking as possible as you really just want to get on with coding and not worry about some pesky program – but there are some basics if you want to make good use of this. The file system is easy enough – you might want to store what’s in your left window – your latest all-singing routine or just a bunch of nonsense – that’s up to you hence file – save. Find a suitable directory to store your stuff – the dialog is bog-standard. For retrieval – you have two options, load and append. The former will overwrite what’s in the window, the latter will append to what’s there – so you can store a load of routines and build up something new the easy way.

Serial is even simpler – open or close the port. When open you’ll find some controls don’t work – like changing the baud rate for example.

Notepad is interesting…yes, no less than 10 pretty coloured notepads (non-volatile) to store snippets in – nothing clever about these, you can just copy and paste to and from them in the normal way.

notepadsI normally have several projects going on and find it handy to have stuff lying around – this beats yellow sticky notes full of code any day. There’s a big CLOSE button at the bottom to hide these.

Clear- well you can clear the notepads or your left or right windows – and help – well it’s a picture of me – the idea of writing a complete help system for this just filled me with horror.

So down at the BOTTOM of the screen… assuming you have the serial all turned on you can “Send Window” – i.e. send the contents of your left window off to the serial port – it will send it one line at a time with a delay between each line specified at the top right in milliseconds, defaulting to 400ms – but whatever works for you.

I’ve coloured the individual panels just to try to help for when you’re in a hurry – I tried to colour the tabs but Microsoft isn’t having any of it up to now.

If you select some text in the normal way in that left panel you can press the “Send Selected” button and only send the stuff that is highlighted – OR you can “copy” from just about anywhere and send whatever is in your clipboard… that’s awfully handy.

Then there are those notes.. N1 to 10 let you send the entire contents of any of those notepads.  Finally there is a one-line window which you can send directly with the “Direct” button.

To the right there are some presets, 9 in all – and in SETTINGS you can define their names and what gets sent out.  And that takes us to settings.

settingsFirstly you’ll see the 9 preset buttons – their titles and contents – note you DO have to press OK to save these in SETTINGS – most things outside of this SETTINGS box just save automatically. Auto prefix and suffix I suggest you leave be unless you’re NOT messing with Lua and the “Auto prefix/Suffix” tickbox determines whether or not you use this – essentially if “File.open” is see starting at the LEFTMOST character in your input window, these prefix/suffix characters will be added to your line as they are being sent out until the system sees a “File.close” again starting in the leftmost column of your input window.

“Arduino DTR” – well that’s for those of you who want to use this terminal with your Arduinos (you may be working with the Espressif AT firmware for example)  – that’s the bit that resets them when you open the port. It just flicks the DTR line temporarily on open – nothing more. Autoclear – tick that and you’ll see the right window cleared every time you press the send button – just preference really. Lua comment removal is turned on by default (—) – you can turned if off – and “Retain blank lines” is new, just something for the future. Normally, most blank lines never make it to the right window.

And that is that, really – nothing much else to tell you about the program – I hope you find it useful – I have – and no doubt I’ll add more in time.

Here’s the Dropbox link (Updated September 18, 2016)  –

https://www.dropbox.com/s/z4836rixvl7tzi0/PetesSerialTerminal.exe?dl=0

Facebooktwittergoogle_pluspinterestlinkedin

esp8266 Annual Awards

esp8266.comJust a note to say THANK YOU to everyone who voted for the Nextion Wifi Touch Display over at esp8266.com in their first annual competition.  I just found out this morning that we won second prize, beaten to the top only by the excellent esp8266 Basic Interpreter – a great tool which will help get beginners up and running with ESP8266 chips.

And this is not the end of this project as the board has proven to be quite useful so we have another iteration on the way soon with an RGB LED as the general indicator and spacing for mounting a DHT11/22 as well as the normal Dallas temperature chip – neatly merging the board into the home control 2016 project.

So once again thanks to those who took the time to vote – quite made my day.

Nextion WIFI Touch Display

Facebooktwittergoogle_pluspinterestlinkedin

Track Broadband Outage in Node Red

connectionActually I could have given this a range of titles – as the following is useful in a range of situations. But first let me explain my problem:

The problem: I’ve been having broadband issues. The broadband cuts out for a few minutes without warning and then reconnects.  I just wasted a lot of time getting onto my router people (TP-Link – they are quite helpful) only to discover the same thing happens with the original rubbish Plusnet router (we’re using high speed fibre-to-cabinet broadband, around 70 meg or so – but it still looks like a normal phone line connection coming into the house so not TOO many modems support this – TP-Link does).

Of course Plusnet and BT say “nothing wrong here mate” and the problem really is intermittent – not had a failure in 2 days now but last week had several in one day. 

The solution: Well, not so much a solution but at least a means to easily monitor any future issues so I can act on them if things get out of hand. The answer for now is to log these events. I set up a routine to log failures by pinging Google every 30 seconds – of course it takes the modem 2 or 3 minutes to recover from a loss of connection so that log was getting large. By version 2 I was only logging CHANGE of state.

Node-Red SQL inject

Above is how I store the info in SQLITE. I use a PING node and the SQLITE node…  and here’s that function in the middle.

context.global.shot=context.global.shot|0;

if (msg.payload===false)
{
if (context.global.shot===0)
    {
        context.global.shot=1;
        msg.topic="insert into pings (ping) VALUES(" + 0 + ")";
        return msg;
    }
}
else
{
if (context.global.shot==1)
    {
        context.global.shot=0;
        msg.topic="insert into pings (ping) VALUES(" + 1 + ")";
        return msg;
    }
}

The actual table is in a database called IOT.DB and here’s the table.

CREATE TABLE 'pings' ('thetime' DATETIME PRIMARY KEY NOT NULL DEFAULT CURRENT_TIMESTAMP, 'ping' INTEGER)

So that’s simply storing away the date and time – and 0 for disconnect, 1 for reconnect.

To make that useful what I needed was for the computer – at one minute to midnight – to send me a report FOR THAT DAY but only if there was actually something to report. That I’ve done below.

image

The first (blue) node is simply a Node-Red inject that sends an empty message at one minute to midnight every night. The second is a function to build up a SQLITE query to get all the events for that day. The last one is an email node set up to send me emails on Gmail.

var now = new Date();
function pad(n) {
    return (n < 10) ? ("0" + n) : n;
}
var today=now.getFullYear() + "-"+pad((now.getMonth()+1))+"-"+ pad(now.getDate());

msg.topic="select * from pings where thetime >= Datetime('"+ today +" 00:00:00') and thetime <= Datetime('"+ today+" 23:59:59')";
return msg;

And finally having sent that off to the SQLITE node, I get an array back of the dates and states… which I send off to myself in email.

msg.topic="Hollyberry Connection Notice";
var a=msg.payload;
msg.payload="";

if (a.length!==0)
{
    for (var i in a)
    {
    msg.payload+="\r\n"+ ((a[i].ping !== 0) ? "Regained" : "Lost") +" connection " + a[i].thetime;
    }
return(msg);  
}

And that, hopefully will keep me informed of any issues with the broadband while we’re away enjoying the sun next week. Hope you find that useful – I’m sure there are many variations of this which might be useful for general monitoring.

Node-Red constantly surprises me with how simple it is to do just about anything I want.

Facebooktwittergoogle_pluspinterestlinkedin

WIFI Public and Private Access Point

OM2PMany moons ago when we first bought our place in Spain (6 days and counting) I bought something called an OM2P – a small white WIFI Access Point. I’m talking several years ago.

What I was after was private WIFI and public WIFI – something I could charge a nominal sum for. Now the reason for this is that at the time, there was very little in the way of WIFI access in the village of Galera (Granada area) and it was costing me a lot for a beamed Internet connection from a company called Iberbanda (we referred to this state owned company as “Iberbandits”).

I figured if I put the access point near the edge of the building, anyone wanting to use it could do so for a nominal sum and that would help pay for the connection.

Today we have high speed Internet over there and I put the unit in a cupboard 2 years ago.  Today I dragged it out wondering whether to throw it away or find a use for it (door-stop perhaps). A quick dusting and it looks as good as new. The unit is interesting as ALL setup is done via the web. You plug it into 12v and your Ethernet – it finds it’s own way to talk to the CLOUDTRAX servers and from there you can go off to a website and control everything.

Convinced they’d have gone bust by now I plugged the unit in and went off to the website.

Not only was my OM2P recognised but I was informed that an update was due – did I wish to go ahead. I agreed and 10 minutes later not only was my OM2P fully updated but also given a whole load of new features – the update is only a couple of months old.  So now this little white wonder can create up to FOUR SSIDs.  I’m not interested in the public side so I switched off the main one. That left three SSIDs to play with.  They can be set up to be just simple access points on the network OR totally isolated.

As it happens when we head off to Spain, our place becomes a holiday rental (www.hollyberry-cottage.co.uk) for the summer and I was struggling with the best way to isolate my various access points from visitors to the cottage. Not only can the SSIDs be made utterly isolated – they can also be bandwidth limited (that’s not working for me – I’ve reported it) and even optionally isolated from each other. If you wish you can make SSID1 accept tokens from credit cards etc and let the public have a little bit of your bandwidth (isolated).. or not.

Good investment.

Facebooktwittergoogle_pluspinterestlinkedin

Duff lights

corn lightsAs everyone in here is into technology – and as that means you’re more than likely to buy LED lighting for your home, I thought I’d take this opportunity to issue a helpful warning – especially for those in 240v AC areas.

While I have generally had great success with modern LED lighting – there is a particular style of light I’d like to flag up here. See the photo – these are often referred to as CORN lights. They come in different sizes and from different suppliers, some Chinese, some home-grown – but from what I’ve seen they all look so similar that they must surely be made by possibly one manufacturer. I could be wrong.

I’ve purchased perhaps a couple of dozen of these over the past couple of years – and EVERY LAST ONE of them has ended up in the bin.  I thought at first I’d just had a bad batch and bought from a separate supplier…then I thought I must be using them in too enclosed an environment as we all know LEDs don’t like heat.

But no, this last one came out of an outside lamp – and right now it is cold in Britain – there is no way this overheated.  My suspicion is that the LEDs are not well matched and being wired in series, it only takes ONE dead LED to bring the whole lamp to a standstill. I assume they’ve done the power this way to save cost.

Either way these are not, as it were, worth a LIGHT. See the picture, you’ll note on a couple of the lights a little black dot in the middle – that is the beginning of the end.

They’re all gone now and I won’t be buying more. I hope that with this short write-up I’ll save others the hassle. They may well last a couple of weeks or a few months – but that in my experience is about it. Meanwhile the little GU-10 lights with three LEDS and proper power supplies I’ve had running 8 hours a day for well over 2 years now with not the slightest degradation – so it’s not LED as such  - it is just down to rubbish design. maybe if you’re on 220v you might get longevity out of these – I can’t say – but at 240-250v – avoid!

Facebooktwittergoogle_pluspinterestlinkedin