Monday, 30 March 2015

ArduinoDay2015 #ArduinoD15 Quick project: Battery capacity tester

Last Saturday was Arduino Day and, of course, I felt obliged to build a little project. As there was just over an hour of ArduinoDay left in my timezone, I had to hurry up and make a few compromises.

The result was this rather simple circuit:

Somehow a relay with two sets of switches had made it into my sparkfun inventor's kit, So I used that second set to switch between two status LEDs, just for the heck of it.
The only thing not contained my (somewhat older) Sparkfun Inventor's kit was a suitable load resistor. I found a 15 Ohms resistor that looked like it could dissipate a few watts. For the 3.7V lithium cell I wanted to test, that should result in a current of approx. 250mA and around 1 Watt of heat that has to be radiated off.


If you want to build this, I'd strongly recommend to use thicker, shorter wires, because the lousy jumper wires and breadboard add an awful lot of resistance.

 int sensorPin = 0;  
 int sensorValue = 0;  
 int time = 0;  
 int rel = 13;  
 float cur = 0;  
 float cap = 0;  
 void setup()  
 {  
 analogReference(DEFAULT);  
 Serial.begin(9600);  
 pinMode(rel, OUTPUT);  
 digitalWrite(rel, HIGH);  
 delay (1000);  
 }  
 void loop()  
 {  
 sensorValue = analogRead(sensorPin);  
 float voltage= sensorValue * (5.0 / 1023.0);  
 if (voltage > 3)  
  {  
  cur = voltage / 15; //current through the 15 Ohms Resistor   
  cap = cap + (cur / 60);   
  Serial.print(time);  
  Serial.print(";");  
  Serial.print(voltage);  
  Serial.print(";");  
  Serial.print(cur);   
  Serial.print(";");  
  Serial.println(cap*1000);   
  delay(60000); //1 minute delay between readings.  
  time++;  
  }  
  else  
  {  
  digitalWrite(rel, LOW);  
  }  
 }  

The sketch cuts out at 3V to protect the cell from deep discharges. That is very safe, but it leaves some capacity in the cell. Keeppower's protection circuits cut off at 2.75V.

I then fed the Time/Volts (the first two columns) to LibreOffice Calc:
Gaaaah! This is one ugly graph. I suppose it is mainly because of contact issues. Thermal effects might also contribute.
On the other hand, the capacity measured is 776 mAh. Not far off for a 800 mAh cell. This is because the current is derived from the voltage drop over the 15 Ohms resistor. And that stays valid, even if the surrounding wiring is poor and adds extra resistance.

Warning: If you need to measure cells over 5V, you need a voltage divider. Otherwise you'll damage your Arduino board. Or at least the microcontroller chip.

Here is the link to my video: https://youtu.be/0tYB6HedLyE

Edit: 20150401 Corrected circuit diagram.

Wednesday, 18 March 2015

Safe makeshift alternative to solar eclipse glasses

The solar eclipse is coming and I am was not prepared!
All special solar eclipse glasses are sold out here and the Kindergarden was desperately looking for glasses for the kids to watch the eclipse.
This morning I had some time and with some household items, I built a camera obscura.
These items alsong with my trusty old tripod make a safe alternative to the special solar eclipse glasses.
The projected image is about 3mm in size, just sufficient to make out the disk of the sun. - And hopefully the missing bits during the eclipse.
That is what the projected image looks like with my digital camera's macro lens.

Looks promising to me.

Here are the instructions in detail:

Edit:
Worked great!


Tuesday, 17 March 2015

NodeMcu 20150317 is out

Just 16 hours ago, what appears to be a dev-version of nodemcu has been released.
Again for me it was a bit hard to find, so here is the link:

https://github.com/nodemcu/nodemcu-firmware/releases/tag/dev_json_20150317

The filesize of the bin files has gone up again, but there is now also an integer binary that saves the memory otherwise needed for float operations.

With the integer binary this obviously results in an error:

 > print (0.5 + 0.5)  
 stdin:1: malformed number near '0.5'  

While that works:
 > print (5 + 5)  
 10  
 >   

Unfortunately my LUA-DNS server doesn't run on any of these two either.



Edit:
Although the filename implies it is version 20150317, it comes up as 20150315:

 node.restart()  
 >  ü!   ¤§1ä)]ô   
 æÇ!åü1¤ñá  
 NodeMCU 0.9.5 build 20150315 powered by Lua 5.1.4  
 lua: cannot open init.lua  
 >   


Wednesday, 4 March 2015

UDP server problem with NodeMCU build 0.95 / nodemcu_20150213.bin

For an upcoming project I need to run a DNS server on the ESP8266 module (ESP-01). All this server has to do is reply to any DNS query with the modules' IP address.
Basically that is what some captive portals do.

I developed that script on nodemcu_20150212.bin without any significant trouble and it ran ok there.

To make use of the node.compile() option, I upgraded to the 20150213.bin but the MCU crashed and rebooted when trying to send back the DNS reply.

The LUA script looks like this:

 svr=net.createServer(net.UDP)   
 svr:on("receive",function(svr,pl)  
 decodedns(pl)  
 encodedns (query, transaction_id)  
 svr:send(response)  
 end)  
 svr:listen(53)  
 function decodedns(pl)  
      --do some magic  
 end  
 function encodedns(query, transaction_id)  
      --do some more magic  
 end  

The svr:send failed and crashed the mcu. It totally lacks all input sanitation and can easily be derailed, but that is another story.

Looking at the changes from 20150212 to 20150213, the only suspicious change was this:

app/lua/luaconf.h
  @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.  
  */  
 -#define LUAL_BUFFERSIZE          BUFSIZ  
 +#define LUAL_BUFFERSIZE          (BUFSIZ*4)  
  /* }================================================================== */  

I changed that back to the original buffer size and sure enough my script was fine again.

Sunday, 1 March 2015

esp8266 lua firmware NODEMCU with node.compile() option

This post may soon be obsolete, so take it with a grain of salt.

I just couldn't get NodeMCUs node.compile() feature to work. I thought I had the latest firmware on the module, because that was what I got as "latest" from github.

The latest firmware (at the time of writing) can be found here:

NodeMCU Firmware Download


 NodeMCU 0.9.5 build 20150213 powered by Lua 5.1.4  
 lua: cannot open init.lua  
 >   
 Hard Restart Sonntag, 1. März 2015 23:38:42  
 for k,v in pairs(file.list()) do l = string.format("%-15s",k) print(l.."  "..v.." bytes") end  
 httpserver.lua  3750 bytes  
 dnsserver2.lua  3554 bytes  
 > node.compile('dnsserver2.lua')  
 node.compile('dnsserver2.lua')  
 > for k,v in pairs(file.list()) do l = string.format("%-15s",k) print(l.."  "..v.." bytes") end  
 dnsserver2.lua  3554 bytes  
 httpserver.lua  3750 bytes  
 dnsserver2.lc   2488 bytes  
 >   

Looking good!

Thursday, 26 February 2015

Inexpensive WAN Emulation with Linux

Quite frequently, when designing a WAN or evaluating a new networked application, it is interesting to try out the „user experience“ rather than believing the manufacturer‘s marketing flyers.
Commercial, closed source WAN emulators, even as pure software solutions are still in the range of approx. 5000€

As we had problems getting a commercial Software package installed under XP (because of - among others - license key issues) we used NETEM under Linux.
That worked flawlessly using Knoppix on a standard PC with two network cards.
Netem does not provide bandwidth management. This can be added easily - see the LARTC Howto or the example below.

In the following example the WAN Emulator is used as a bridge, i.e. without Layer 3 routing.

Simulating layer 2 ethernet connections has gained relevance since I did my tests in late 2006: Telco providers, eg. Colt, now offer national and international ethernet connections. These can be simulated realistically with the method described here.

Script to enable WAN emulation under Knoppix:

brctl addbr goldengate
brctl addif goldengate eth0
brctl addif goldengate eth1
ip link set up dev goldengate
ip link set up dev eth0
ip link set up dev eth1
ip link show
brctl showmacs goldengate

tc qdisc add dev eth0 root handle 1:0 netem delay 27ms
tc qdisc add dev eth0 parent 1:1 handle 10: tbf rate 1000kbit buffer 16000 limit 30000

tc qdisc add dev eth1 root handle 2:0 netem delay 27ms
tc qdisc add dev eth1 parent 2:1 handle 20: tbf rate 1000kbit buffer 16000 limit 30000

tc -s qdisc ls dev eth0
tc -s qdisc ls dev eth1


Disable:


tc qdisc del dev eth0 root handle 1:0

tc qdisc del dev eth1 root handle 2:0

tc -s qdisc ls dev eth0
tc -s qdisc ls dev eth1


In the 13/08 edition of the German c‘t magazine, an article about WANEM was published. While it‘s focus is apparently on routed links, the GUI it comes with mightbe interesting to try.

How to recover data from a NT4 volume set

How to recover data from a NT4 volume set
recently the boot disk of a NT4 server at work failed. The system reported missing files and wouldn't come up properly.
A colleaugue of mine tried a NT4 repair install from the original NT4 SP1 CD.
That fixed the operating system, but as we had no emergency repair floppy, the config details were lost.
The box had three scsi drives, with the first one DISK0 (having two NTFS partitions) as the boot drive. NT4's hard disk manager only found two disks with unknown partitions.
As I had no idea what we were up against, I booted a Knoppix CD and looked at the file system types, which were:

0x87 on DISK1 and 0x86 on DISK2.

Information on fs-type 87 and 86 on the web were a bit shaky, but it seemed like these two disks might have been part of volume set. Mounting any of the drives in Knoppix didn't work, even when explicitly telling mount to use NTFS.
One of our developers confirmed that the server had „a big e-drive“. That sounded like our volume set.
Someone found an old NT4 Server resource kit in the basement while searching for a NT4 server cd. This came really handy:
With the „ftedit“ program from the resource kit, I could see that the server didn't have any information about the volume set. The manual in the resource kit said that these details are stored in:

HKEY_LOCAL_MACHINE/SYSTEM/DISK

I then discovered a SYSTEM._ file in the WINNT/REPAIR directory which I expanded to a file on a floppy disk. Opening that file on an other machine with a freeware „offline registry viewer“ (MiTeC Registry File Viewer), I exported the DISKS key to a .reg file and imported that key back into the nt4 server.
After a reboot the disk manager showed the two drives (DISK1 DISK2) as a volume set.
The same could have been achieved with ftedit manually. Ftedit only manipulates the registry. It doesn't touch the disks as such. So the risk is relatively low.
A drive letter „E“ was attached to the volume, but the file system type still read „unknown“ in the disk admin tool.
I then installed Service Pack 6a, because I thought NT4SP1 couldn't recognize the partition type. Although it didn't fix the problem, it is certainly a good idea to do so.
After some more research (read: goooooooogling), I found the last missing clue here:

http://support.microsoft.com/?scid=kb%3Ben-us%3B131658&x=4&y=17

The ftdisk service in the device manager had to be set to start with the system.
Even starting it manually from the control panel immediately brought back the missing E-drive.
Obviously the fresh OS-install had not started that service as no fancy disk configs were made from that installation.

Lesson learned: create emergency repair disks for all remaining NT4 servers (rdisk)