TP-Link HS110

For issues with communication ports, protocols, etc.
badidea
Posts: 2122
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TP-Link HS110

Postby badidea » Nov 06, 2019 16:57

Dinosaur wrote:@badidea, dowloaded the zip and it compiles ok, but when I run it:
"Waiting for connection" and then quits with Error 141.

I could not find anywhere in the code where your IP detail is stored.
Without thoroughly reading all the code can you explain this please, so I can test it for a long duration.

In "HS110_power_logger_03.bas", line 263:
retCon = hs110.connect("HS110-1", 9999)
Change "HS110-1" with your IP and try again.

Error 141 seems to be: "SIGPIPE, The SIGPIPE signal is sent to a process when it attempts to write to a pipe without a process connected to the other end." Or: "Write on a pipe with no one to read it".

BTW: Getting the code Windows compatible will be some work. My non-blocking connect() addition to SNC gives a few errors:

Code: Select all

C:\Tools\FreeBASIC-1.04.0-win32\fbc.exe -w all "HS110_power_logger_03.bas" (in directory: D:\Projects\FreeBASIC\hs110\HS110_power_logger)
D:\Projects\FreeBASIC\hs110\HS110_power_logger\inc\snc.bi(318) error 41: Variable not declared, fcntl in 'dim as long flags = fcntl(sock, F_GETFL, NULL)'
D:\Projects\FreeBASIC\hs110\HS110_power_logger\inc\snc.bi(321) error 3: Expected End-of-Line, found 'fcntl' in 'fcntl(sock, F_SETFL, flags or O_NONBLOCK)'
D:\Projects\FreeBASIC\hs110\HS110_power_logger\inc\snc.bi(339) error 14: Expected identifier, found 'socklen_t' in 'dim as socklen_t optlen = sizeof(optval)'
D:\Projects\FreeBASIC\hs110\HS110_power_logger\inc\snc.bi(340) warning 3(1): Passing different pointer types, at parameter 4 of GETSOCKOPT()
D:\Projects\FreeBASIC\hs110\HS110_power_logger\inc\snc.bi(340) error 41: Variable not declared, optlen in 'getsockopt(sock, SOL_SOCKET, SO_ERROR, @optval, @optlen)'
D:\Projects\FreeBASIC\hs110\HS110_power_logger\inc\snc.bi(349) error 9: Expected expression, found 'fcntl' in 'flags = fcntl(sock, F_GETFL, NULL)'
D:\Projects\FreeBASIC\hs110\HS110_power_logger\inc\snc.bi(351) error 3: Expected End-of-Line, found 'fcntl' in 'fcntl(sock, F_SETFL, flags and not(O_NONBLOCK))'
Compilation failed.

The main issue seems to be 'fcntl'
Dinosaur
Posts: 1357
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: TP-Link HS110

Postby Dinosaur » Nov 06, 2019 19:14

Hi All

Just making sure I have everything right before I leave the Power monitor running for a day or two.
Changed the location of the plug to record my frequent coffee boils.
The kettle shows the following:
1500 Watt
120 VAC
Being a resistive element, I guess the power factor will be close to 1.
The following is what was recorded.

Code: Select all

13:00:38   123.946   13.828   1703.844   0.994
13:00:39   123.829   13.859   1713.343   0.998
13:00:40   123.879   13.835   1711.153   0.998
13:00:41   124.057   13.819   1711.537   0.998
13:00:42   124.114   13.797   1709.732   0.998
13:00:43   124.053   13.776   1706.245   0.998
13:00:44   123.974   13.752   1702.143   0.998
13:00:45   123.953   13.738   1700.172   0.998
13:00:46   123.968   13.728   1699.176   0.998
13:00:47   123.897   13.713   1696.351   0.998
13:00:48   123.865   13.703   1694.674   0.998
13:00:49   124.061   13.714   1698.752   0.998
13:00:50   124.184   13.709   1699.767   0.998
13:00:51   124.081   13.715   1699.154   0.998
13:00:52   124.264   13.719   1702.154   0.998
13:00:53   124.102   13.709   1698.654   0.998
13:00:54   124.128   13.699   1697.931   0.999
13:00:55   124.039   13.698   1696.542   0.999
13:00:56   123.959   13.700   1695.554   0.998
13:00:57   124.088   13.696   1696.953   0.998
13:00:58   124.183   13.693   1697.972   0.999
13:00:59   124.159   13.697   1697.956   0.998
13:01:00   124.198   13.698   1698.651   0.998
However the display shows the Wattage as crawling along the 0 (zero) mark.
The Voltage shows correctly around 120 and the Amperage also just above 0.
I noticed that the graticule is graduated from 0 to 100 for the wattage, are you considering automatic scaling or switches to set it?

Regards
EDIT: Another suggestion is to have a re-read of the file and displaying it at a rate of say 1 min = 1sec and a Pause button to allow observation
of an event. About 25 years ago I built a weigher for diamonds at 3 per second. The diamonds slid down a tube that was weighed. The software
had to many features to mention, but it looked for a "flat stable spot" and used that weight to classify the diamond into a catagory.
Unfortunately none of that software is allowed to be used.
badidea
Posts: 2122
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TP-Link HS110

Postby badidea » Nov 06, 2019 20:06

badidea wrote:More stuff to do:
- Line plots instead of dots
- Rolling plots
- Auto-scale plots
- Test with Windows

Also, the plots are not designed for > 1 hour operation. Working on that. The logging should continue to work.
For now, you can change scaling in 'set_graphs.bas'
badidea
Posts: 2122
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TP-Link HS110

Postby badidea » Nov 07, 2019 23:37

Making some progress. Auto-scale based on data in plots (e.g. last 5 minutes) and line-plots.
Now the y-axis numbers are a bit weird. Each plot probably needs a different scaling strategy.
* power factor: Always 0 ... 1
* voltage: Rounding up and down (e.g. for plot below: 241 ... 243 V)
* power & current maybe always from 0 to a nice number like 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, etc.
Image
Dinosaur
Posts: 1357
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: TP-Link HS110

Postby Dinosaur » Nov 08, 2019 0:54

Hi All

Jeez those pics bring back memories.
My experience with this is to initialize the scale to the higher range, and then I usually
scale the screen to see the critical area I am interested in.
Clipping the top of the spikes in those circumstances are ok, as long as you get the detail
in the area you are interested in.

BUT, I guess if you need a lot of detail you get a cro .

Regards
badidea
Posts: 2122
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TP-Link HS110

Postby badidea » Nov 10, 2019 0:59

I have updated my power logger:
- Works with Windows again
- Rolling plots
- Auto scaling y-axis

Source: https://nr100.home.xs4all.nl/badidea/HS ... logger.zip

Device IP can be set in variable 'deviceNameOrIp' (line 274 of 'HS110_power_logger_04.bas')
Display time can be set in constant 'GRAPH_X_SCALE' (line 270 of 'HS110_power_logger_04.bas')

I don't have a plan for a detailed interface with zooming on data. Data is also written to file for further analysis options.

Technical note:
For Windows, I switched back to the standard client connect call. I could not get the connect working with a fixed timeout. Maybe Windows does not support this. Not a big issue as the standard timeout under Windows is much shorter then under linux. I can look further into setting the number of retries so that linux and Windows behave the same. With freeBASIC version of:

'int synRetries = 2; // Send a total of 3 SYN packets => Timeout ~7s
'setsockopt(fd, IPPROTO_TCP, TCP_SYNCNT, &synRetries, sizeof(synRetries));
Dinosaur
Posts: 1357
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: TP-Link HS110

Postby Dinosaur » Nov 10, 2019 16:00

Hi All

Great work badidea, love the auto scaling.
Only one complaint, when the screen is set for 1024x768 the text at the bottom is not readable.
Same issue I had with the 7" screen, that is the Title bar.
BY resetting it to 1024x738 it works, but the graticule becomes a bit distorted.

I will test further.

Regards
badidea
Posts: 2122
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TP-Link HS110

Postby badidea » Nov 15, 2019 19:27

Hi Dinosaur, I saw your mail today. With only one hs110, I don't need a full featured GUI. But if you look for a 'beta-tester', I can give it a try.
Dinosaur
Posts: 1357
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: TP-Link HS110

Postby Dinosaur » Nov 19, 2019 1:52

Hi All

badidea thanks for the offer, and like to take you up on that.
I can only test so much, but as soon as you install it, there will probably be totally different problems.
Although I am happy with the performance and functions, there are little annoyances like delays
in focus when selecting buttons, but I will solve that.

Sent you a PM with the download link.

Regards
badidea
Posts: 2122
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TP-Link HS110

Postby badidea » Nov 23, 2019 22:55

Dinosaur wrote:Sent you a PM with the download link.

I finally gave it a try. But I am having trouble with allegro.

The liballeg.so and liballeg.so.4.4 that you included are symbolic links.
I installed liballeg.so.4.4.2 from the package manager and added a symlink sudo ln -s liballeg.so.4.4.2 liballeg.so
But it results in a run-time error:

Code: Select all

/home/badidea/hmi/
Pinging 192.168.0.181
FATAL ERROR, Router Unreachable.
Check if selected Wifi network is correct,
or the Router power is Off
Error installing allegro
------------------
(program exited with code: 255)
Press return to continue

Changing the symlink to liballegro.so.5.2.3 (which I had already installed) does not improve things.
Also the CGUI example (hello.bas) shipped with freebasic gives the same error.

I will try some more things...

Another thing I noticed is that your cgui.bi ("2.1.0") seems different then the version I had ("2.0.4").

Edit:
The weird thing is that the 5 allegro examples (in examples/graphics/Allegro) shipped with freebasic work fine.
The allegro5 example (in examples/graphics/Allegro5) crashes (with both symlinks): Segmentation fault (core dumped)


Edit2:
I have libcgui working now. I had to build version 2.1.0 (from https://sourceforge.net/projects/cgui/files/).
I will try your tool now. First thing I notice is the my laptop fan spinning up.
Dinosaur
Posts: 1357
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: TP-Link HS110

Postby Dinosaur » Nov 23, 2019 23:55

Hi badidea

I was afraid that Allegro was going to be the stumbling block.
I have zipped the library onto my site, so if you just change badidea.zip to liballeg.zip you can download it.

The program starts by checking the Router or first device.
However you can't edit the first device or Router if you can't load Allegro.

I am interested if simply putting the library into /usr/local/lib will allow it to work.
First thing I notice is the my laptop fan spinning up.

Yeah not to many sleeps, but the BBB runs cool.

Regards

Edit:The Allegro.cfg included in the zip has to be in the same folder as the executable or set as Environment variable ALLEGRO=/.....
It only has one setting to allow the display of sec's on the time
badidea
Posts: 2122
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TP-Link HS110

Postby badidea » Nov 24, 2019 0:14

With the newly build libcgui it works. I can control my 'Kitchen Kettle'.

Here I was trying the 'Log In' button:
Image
Dinosaur
Posts: 1357
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: TP-Link HS110

Postby Dinosaur » Nov 24, 2019 0:19

Hi Badidea

Code: Select all

MStatus.Level = 3               'so we can see / edit all detail

You already have full access, and if you look through the code you will find my birthday.

Regards

Edit:
I note your scan time is zero as it is on my laptop, but it increase to about 10 on the BBB and goes into the hundreds when running.

Some fixes and changes made since I sent you the zip file.
If E-stop pressed , the Schedule quits, but would not restart after release of E-Stop and press of Run button.
If program started after a schedule has elapsed, the Smarty was not turned OFF.(if that was part of the schedule)
As BBB does not have a RTC and relies on NTP to sync the time, prevent a schedule from being acted on if Time not synced.
Some help text files were missing.
badidea
Posts: 2122
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TP-Link HS110

Postby badidea » Nov 24, 2019 11:32

Dinosaur wrote:You already have full access, and if you look through the code you will find my birthday.

Only 31 years difference :-)

I will try the schedule later. Other things to do today.
Dinosaur
Posts: 1357
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Re: TP-Link HS110

Postby Dinosaur » Nov 24, 2019 16:36

Hi All

Other things to do today.
Me too.
Next step is to integrate a HS200 switch so that I have a "person operated" input into the program.
Haven't found the protocol for that yet.
Whilst looking found this, https://www.openhab.org/docs/
but decided it is to involved for my simple application, plus I have no intention of getting involved with Java.

Regards

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest