aelveborn / Wii-Scale

Turns your Wii Balance Board into a scale and presents your weight on a responsive website. Runs Linux and works on your Raspberry Pi.
http://aelveborn.github.io/Wii-Scale/
GNU General Public License v2.0
118 stars 27 forks source link

Switch back-end from Python to C++ #17

Closed ribbons closed 6 years ago

ribbons commented 7 years ago

Following on from #14, this is a considerably improved version which I think is now much more like something that could actually be merged.

I've addressed the following issues since my original PR:

I've not implemented pairing via the UI as this is available either via the user's desktop environment, or via bluetoothctl for headless boxes and only needs to be done once.

Dependencies

This is a hopefully complete list of the dependencies required for building under KDE Neon (and other Ubuntu-based distros):

sudo apt-get install g++ make cmake cppcheck libboost-all-dev libxwiimote-dev libglibmm-2.4-dev libudev-dev

These might be slightly different under Raspberry Pi, but should be broadly similar - unfortunately I don't have a spare Pi I can use for testing at the moment.

Once the dependencies are installed, it should just be a case of following the build steps in the README.

ribbons commented 7 years ago

Okay, I've added a workaround for the missing address value under /sys/devices - if I have understood correctly, this should fix the issue that @n1zzo was hitting and with a bit of luck may also fix things for @nico202 and @Esylias. I'll await feedback from you all with baited breath!

n1zzo commented 7 years ago

Hi @ribbons, I've just tried it on my RaspberryPi, and it works flawlessly! Just one thing...it was not compiling with this error:

[.../wii-scale/BlueZDevice.cpp:26]: (performance) Function parameter 'name' should be passed by reference.
make[2]: *** [CMakeFiles/cppcheck.dir/build.make:57: CMakeFiles/cppcheck] Error 2
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/cppcheck.dir/all] Error 2
make: *** [Makefile:128: all] Error 2

Fixed it in this way:

diff --git a/wii-scale/BlueZDevice.cpp b/wii-scale/BlueZDevice.cpp
index a34b0cb..bf67252 100644
--- a/wii-scale/BlueZDevice.cpp
+++ b/wii-scale/BlueZDevice.cpp
@@ -23,7 +23,7 @@
 #include "BlueZDevice.h"

 template <class retType>
-retType GetPropertyValue(Glib::VariantBase properties, std::string name)
+retType GetPropertyValue(Glib::VariantBase properties, const std::string &name)
 {
     Glib::VariantIter valuePairsIter(properties);
     Glib::VariantContainerBase container;

I think you should make this change also in other places where you have to pass a string as a parameter. Thank you for the bugfix!

ribbons commented 7 years ago

I've just tried it on my RaspberryPi, and it works flawlessly!

Awesome, that is great news!

Just one thing...it was not compiling with this error: ...

Ah, yes - must be a newer version of cppcheck.

I think you should make this change also in other places where you have to pass a string as a parameter.

Agreed - have just pushed a commit to address that.

@nico202 and @Esylias - does the fix improve matters for you?

nico202 commented 7 years ago

@ribbons I have internet again! (yes, my life is sad) checkout, compile, and.. yes! It's working for me :)

ribbons commented 7 years ago

@ribbons I have internet again! (yes, my life is sad) checkout, compile, and.. yes! It's working for me :)

Great :smile:

@Esylias - does the latest code in this PR fix things for you?

Esylias commented 7 years ago

@ribbons i solved my project with an flowmeter :)

ribbons commented 7 years ago

@ribbons i solved my project with an flowmeter :)

Erm, okay...

In that case @aelveborn, from my point of view this is ready to merge (though if you want to merge #20 first instead I'll need to quickly rebase this before merging).

Nauttor commented 7 years ago

Hi ribbons,

Since my last update it works as expected, but today it suddenly stop working. I haven´t change anything on my system afterwards. It´s quite strange, the board It´s paired and connected correctly, the led stay on, I push the connect button on the gui and it change to disconnect in red. All appears to be ok, but then no change in the weigh is displayed. I stand up on the board and nothing happends. I try to unapir remove and add again from scratch the board on bluetoothclt, nothing happends. How can I debug what happens , I use it on a daily basis so if there is a bug I´m gonna find it soon or later.

ribbons commented 7 years ago

Since my last update it works as expected, but today it suddenly stop working. I haven´t change anything on my system afterwards. It´s quite strange, the board It´s paired and connected correctly, the led stay on, I push the connect button on the gui and it change to disconnect in red. All appears to be ok, but then no change in the weigh is displayed. I stand up on the board and nothing happends. I try to unapir remove and add again from scratch the board on bluetoothclt, nothing happends. How can I debug what happens , I use it on a daily basis so if there is a bug I´m gonna find it soon or later.

Could you check if xwiishow reports weight values from your board which change when you step on it?

Nauttor commented 7 years ago

I check with the xwiishow as you suggest, and I realize that the board does not show data on the gui neither. So I replace the batteries and voilá, it appears to be working again. So, sorry for bother you. It´s quite weird that behaviour, it apparently works and pair but do not measure. Do you know if the board send battery status data? It would be awesome to show that on the Web GUI.

Again thanks for your help.

Regards.

ribbons commented 7 years ago

I check with the xwiishow as you suggest, and I realize that the board does not show data on the gui neither. So I replace the batteries and voilá, it appears to be working again. So, sorry for bother you.

Great - glad it was a straight-forward fix.

It´s quite weird that behaviour, it apparently works and pair but do not measure. Do you know if the board send battery status data? It would be awesome to show that on the Web GUI.

Yes, I believe that battery status is available - it is certainly one of the things I'd like to start working on once this PR is merged.

aelveborn commented 7 years ago

@ribbons I think we can skip PR #20. You were right, I did include the build folder for ppl to skip compiling the frontend, and I think as of right now that's still the best option since this is a small project. Is this PR ready to be reviewed and merged?

ribbons commented 7 years ago

@ribbons I think we can skip PR #20. You were right, I did include the build folder for ppl to skip compiling the frontend, and I think as of right now that's still the best option since this is a small project. Is this PR ready to be reviewed and merged?

Okay, have closed #20. Yes, this is ready for reviewing and merging :smile:.

n1zzo commented 7 years ago

Hi @ribbons, I am so sorry to report this because I want this to be merged quickly, and opening new issues will only slow the thing down. The fact is that after a day of activity the webpage becomes unresponsive, and this appears on the log of my systemd service:

May 28 10:42:09 pyre npm[319]: [2017-05-28 10:42:09] [connect] WebSocket Connection 127.0.0.1:8080 v-2 "WebSocket++/0.7.0" /socket.io/?EIO=4&transport=websocket&t=1495968129 101 May 29 06:38:27 pyre npm[319]: terminate called after throwing an instance of 'std::runtime_error' May 29 06:38:27 pyre npm[319]: what(): Could not find path for Bluetooth name "Nintendo RVL-WBC-01"

When I'll have more time I'll try to put together the steps to reproduce this, in the meanwhile do you have some ideas?

ribbons commented 7 years ago

May 28 10:42:09 pyre npm[319]: [2017-05-28 10:42:09] [connect] WebSocket Connection 127.0.0.1:8080 v-2 "WebSocket++/0.7.0" /socket.io/?EIO=4&transport=websocket&t=1495968129 101 May 29 06:38:27 pyre npm[319]: terminate called after throwing an instance of 'std::runtime_error' May 29 06:38:27 pyre npm[319]: what(): Could not find path for Bluetooth name "Nintendo RVL-WBC-01"

When I'll have more time I'll try to put together the steps to reproduce this, in the meanwhile do you have some ideas?

I figured out a way to reproduce this error - clicking twice quickly on the Disconnect button. This fires off two requests to disconnect, the second of which fails while working out the path due to the board having just disconnected.

I will try and make some time over the next couple of evenings to see how I can prevent this bug occurring.

ribbons commented 7 years ago

Right, I've just pushed a commit which should fix the issue you ran into @n1zzo, so this PR is back to being ready for review and merge @aelveborn :smile:.

n1zzo commented 7 years ago

Nice work! I can confirm that the problem is fixed now. Thank you for your awesome support @ribbons!

gppk commented 7 years ago

I'm having issue building this on the RPi, I get the following error when i try to build, any thoughts?

I downloaded your git from here - https://github.com/ribbons/Wii-Scale, if i used the master here then I didn't have any of the files


` cmake ../wii-scale && make
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.55.0
-- Found the following Boost libraries:
--   program_options
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.28")
-- Checking for module 'giomm-2.4'
--   Found giomm-2.4, version 2.42.0
CMake Error at CMakeLists.txt:26 (add_subdirectory):
  The source directory

    /home/pi/Documents/Wii-Scale/wii-scale/socket.io-client-cpp

  does not contain a CMakeLists.txt file.

-- Configuring incomplete, errors occurred!
See also "/home/pi/Documents/Wii-Scale/build/CMakeFiles/CMakeOutput.log".
``
ribbons commented 7 years ago

I'm having issue building this on the RPi, I get the following error when i try to build, any thoughts?

From the error message you are getting I'd suspect that you've not checked out the submodules as well, try doing a git submodule update --init --recursive and then try again.

Nauttor commented 7 years ago

Hey ribbons,

do you remember that strange error I told you before about the graph, it happends again.

As I told you I´m an intensive user of the system, my wife to be more concrete, and the error persist, the graph stop drawing after april 8. I attach below a screen cap just for the record.

screen shot 2017-06-21 at 19 14 40

any idea how to fix this?

ribbons commented 7 years ago

Hey ribbons,

do you remember that strange error I told you before about the graph, it happends again.

As I told you I´m an intensive user of the system, my wife to be more concrete, and the error persist, the graph stop drawing after april 8. I attach below a screen cap just for the record.

any idea how to fix this?

I'm not that familiar with the front-end code, I suspect @aelveborn would be able to shed more light on the subject, but as it isn't related to the new backend, I'd say it would be a good idea to raise a new issue for it.

aelveborn commented 6 years ago

Hey @ribbons, do you think your PR are ready to be merged?

ribbons commented 6 years ago

Hey @ribbons, do you think your PR are ready to be merged?

Hey! Yes, all ready to go :+1:

floek commented 6 years ago

Hey @aelveborn would be nice if you could accept the merge request.

ribbons commented 6 years ago

Have just pushed a small update to this PR which fixes compilation of the socket.io client under Arch Linux.

tectiv3 commented 6 years ago

Hi! First of all thank you, I've installed and built everything on rpi3 without any problems.

My question is - do I have to turn over the board and press sync button every time? Cause after I click disconnect - I can't connect it again.

ribbons commented 6 years ago

My question is - do I have to turn over the board and press sync button every time? Cause after I click disconnect - I can't connect it again.

No, you should only need to do that once during the initial pairing with your Pi (outside of the Wii-Scale application). Once you've done that you can just press the balance board button.

Have you paired the board with your Pi using the desktop application / widget or bluetoothctl if you don't have a desktop environment installed?

tectiv3 commented 6 years ago

I'm sorry I should've mentioned it, the answer is yes. I have it paired and trusted. And after disconnect I have to open bluetoothctl, press red button on the pad and run connect command before I can click connect on the UI.

ribbons commented 6 years ago

I'm sorry I should've mentioned it, the answer is yes. I have it paired and trusted. And after disconnect I have to open bluetoothctl, press red button on the pad and run connect command before I can click connect on the UI.

The application isn't triggering a bluetooth level connect (it is checking for a connected device and connecting to it), so that would make sense. Sounds like your balance board isn't connecting automatically for some reason.

I'm slightly fumbling in the dark but according to this link I just turned up: https://github.com/jgeumlek/MoltenGamepad/wiki/Wiimote-Pairing you might find that completely clearing the balance board from bluetoothctl and then doing a pair immediately followed by a connect fixes the issue (my understanding is that the balance board internals function in a very similar fashion to the Wiimotes). If that doesn't work I guess it is down to the standard kinda troubleshooting - certainly bluetoothctl needs to show the balance board as connected before the application can see it.

tectiv3 commented 6 years ago

certainly bluetoothctl needs to show the balance board as connected before the application can see it.

I understand that, my question is more about workflow. Do you have it always connected (e.g. you are using wall charger) or pushing front button is enough for it to connect automatically?

ribbons commented 6 years ago

I understand that, my question is more about workflow. Do you have it always connected (e.g. you are using wall charger) or pushing front button is enough for it to connect automatically?

Yes, pushing the front button is enough for the balance board to connect automatically.

tectiv3 commented 6 years ago

completely clearing the balance board from bluetoothctl and then doing a pair immediately followed by a connect fixes the issue...

Indeed it does! Thank you!

ribbons commented 6 years ago

Thanks @aelveborn :smile:

Indeed it does! Thank you!

Great, glad that fixed the issue for you :+1:

aelveborn commented 6 years ago

@ribbons np, you did amazing work. Sorry it took so long..