tsathishkumar / MySController-rs

Controller for MySensors, exposes WoT APIs for the sensors. It supports OTA firmware updates, and also acts as proxy for all requests.
GNU Affero General Public License v3.0
20 stars 9 forks source link

Installation on Mozilla Gateway Pi image #30

Closed flatsiedatsie closed 5 years ago

flatsiedatsie commented 6 years ago

For anyone looking for some help, here is the step-by-step process of getting this to run on the Mozilla Gateway Raspberry Pi image (0.6.1).

1. Get all the supporting software

First, login to your Raspberry Pi via SSH. Make sure the "enable SSH" option is set in the Mozilla Gateway interface (under Settings -> Developer).

Let's get the latest versions of the repositories, so your system knows what all the latest versions are, using this command:

sudo apt-get update

Next, we need to install Rust. It's the programming language in which MySController-rs was written.

sudo curl https://sh.rustup.rs -sSf | sh

Here you will be asked a question during the installation procedure. Choose ‘modify installation’ and select to install the beta version of rust. Keep the rest of the options at their defaults (simply press enter in those cases).

Next, we need to install some things this project relies on.

sudo apt-get install libssl-dev libsqlite3-dev

2. Create a settings file

Let's also create a settings file now. (And you use the same command again later if you want to change the settings). Type:

sudo nano /etc/myscontroller-rs/conf.ini

You are now editing a text file with a program called 'nano', a rudimentary text editor. Depending on that need, copy one of these two texts into it (ctrl-C and ctrl V on windows/linux, CMD-C and CMD-V on mac):

Option A. If you are using a serial gateway for MySensors (an Arduino connected via USB), use this:

[Gateway]
;type=TCP
;port=0.0.0.0:5003
type=SERIAL
port=/dev/ttyUSB0
baud_rate=115200

[Controller]
type=TCP
port=0.0.0.0:8088

[Server]
database_url=/var/lib/myscontroller-rs/sqlite.db

Option B. If you are using the ethernet variety, use this:

[Gateway]
type=TCP
port=0.0.0.0:5003
;type=SERIAL
;port=/dev/ttyUSB0
;baud_rate=115200

[Controller]
type=TCP
port=0.0.0.0:8088

[Server]
database_url=/var/lib/myscontroller-rs/sqlite.db

(and don't forget to also install the MySensors gateway software)

3. Get the code

OK, time to get the code and turn that code into the actual program. Type:

git clone https://github.com/tsathishkumar/MySController-rs.git

then

cd MySController-rs

and then

sudo cargo run

Great, now go make yourself a cup of tea. This should take about 15 minutes.

A lot of things will scroll by in the mean time. It will start with:

    Updating crates.io index
  Downloaded http v0.1.14                                                       
  Downloaded log v0.4.6                                                         
  Downloaded serde_derive v1.0.80                                               
  Downloaded byteorder v1.2.7                                                   
  Downloaded smallvec v0.6.6                                                    
  Downloaded r2d2 v0.8.3                                                        
  Downloaded actix-web v0.7.14                                                  
  Downloaded lazy_static v1.2.0  

..followed by things like this..

   Compiling libc v0.2.44                                                       
   Compiling proc-macro2 v0.4.24                                                
   Compiling rand_core v0.3.0                                                   
   Compiling cfg-if v0.1.6                                                      
   Compiling nodrop v0.1.13                                                     
   Compiling byteorder v1.2.7                                                   
   Compiling lazy_static v1.2.0                                                 
   Compiling failure_derive v0.1.3                                              

..and as it finally gets to the heart of the matter, the MySController code itself, you may start to see a lot of warnings like:

   Compiling myscontroller-rs v0.6.5 (/home/pi/MySController-rs)                
warning: cannot find type `table` in this scope                                 
   --> <::diesel::macros::table_body macros>:165:33                             
    |                                                                           
165 | derive ( Debug , Clone , Copy , QueryId ) ] /// The actual table struct   
    |                                 ^^^^^^^ names from parent modules are not accessible without an explicit import
    |                                                                           
    = note: #[warn(proc_macro_derive_resolution_fallback)] on by default        
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>

Don't be alarmed. They are not a problem.

Finally, you will see:

    Finished dev [unoptimized + debuginfo] target(s) in 22m 03s                 
     Running `target/debug/myscontroller-rs`

The controller should now be running.

Now, it may well crash now with an error at this point. Something like:

thread 'main' panicked at 'calledResult::unwrap()on anErrvalue: .. followed by the precise error message.

If so, do a search here and in google to learn more about the issue. You might find tips on how to fix it yourself. If you don't see any reference to the error, create a new issue here, and share in detail how you arrived at the issue. Mention things like the version of the Mozilla Gateway, the hardware you're running, that type of MySensors gateway you use (software or Serial Arduino).

Done!

Keep your terminal window open for now, as it will allow us to see what is going on under the hood.

4. Get the devices into Mozilla Gateway.

Finally open the Mozilla Gateway interface and go to Settings -> Add-ons. Configure the Web Things add-on, and add this url there:

http://127.0.0.1:8888

Now, you can try powering up your MySensors devices one by one. You should see a lot of activity in the terminal window. After finding each device the software should restart itself. Give it a few minutes. Restart your arduino's after they have been found too.

Try clicking the "add things" button in the Mozilla Gateway interface. You should now see the devices.

TROUBLESHOOTING

During the device discovery phase you can 'look under the hood' by opening these url's in your browser:

http://[YOUR CONTROLLER'S IP ADDRESS HERE]:8000/nodes http://[YOUR CONTROLLER'S IP ADDRESS HERE]:8000/sensors http://[YOUR CONTROLLER'S IP ADDRESS HERE]:8888

(so for example: http://192.168.1.110:8000/nodes)

They will list all the devices that have been found. If they haven't (yet), then you will only see: []

tsathishkumar commented 6 years ago

@flatsiedatsie Thanks a lot for writing this up 👍 I have created a page instead of the issue.