Metadata-Version: 2.4
Name: mkconnect
Version: 0.1.0
Summary: MouldKing Bluetooth hub connector
License: MIT License
        
        Copyright (c) 2024 J0EK3R
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# mkconnect-python
...a bit of code to connect to MouldKing Bluetooth Hubs in python.

# MouldKing Hubs
## MouldKing 6.0 Hub
The MouldKing 6.0 Hub has two modes:
* RC-Mode to be controlled with a MouldKing remotecontrol
* Bluetooth-Mode to be controlled with an app

You can control a maximum of three MK6.0 Hubs at the same time with bluetooth.
> (Currently this project can send only one advertising telegram the same time - so only one hub can be controlled, all others will go in timeout-mode till next telegram with their device address is sent.)

## Setting the address of the Hub
To switch the Hub's device address to the next one (device 0, device 1, device 2) just press the button on the hub.

> i.E.: If the script runs with **mkcontrol(2,0,1)** (-> device2, channel0, full speed forward) and nothing is happening, you have to short-press the button, perhaps again...)

# usage
Start the script [consoletest.py](https://github.com/J0EK3R/mkconnect-python/blob/main/consoletest.py) on your raspberry:
```
pi@devpi:~/dev/mkconnect-python $ sudo python -i consoletest.py 
```

## mkbtstop() - stop bluetooth advertising
```
Ready to execute commands

>>> mkbtstop()
```

## mkconnect() - switch hubs in bluetooth mode
If you power-on the hubs they will listen to telegrams to the **first device by default**.
Call mkconnect() to switch all hubs in Bluetooth mode.
By short-pressing the button on MK6.0 Hubs you can choose the hubId:
* hubId=0 - one Led flash
* hubId=1 - two Led flashs
* hubId=2 - three Led flashs
```
Ready to execute commands

>>> mkconnect()
```

## mkcontrol(deviceId, channel, power and powerAndDirection)
i.E.: mkcontrol(0, 0, 1) - on first device (deviceId=0) run channel A (channel=0) with fullspeed (powerAndDirection=1)
```
Ready to execute commands

>>> mkcontrol(0, 0, 1)
```

## mkstop(deviceId)
Set all channels of device to zero
```
Ready to execute commands

>>> mkstop(0)
```

---
# old stuff

There is a testscript [consoletest.py](https://github.com/J0EK3R/mkconnect-python/blob/main/consoletest.py) where (on raspberry pi) **hcitool** is used to advertise telegrams over bluetooth.

Maybe you habe to **sudo** the command:
```
pi@devpi:~/dev/mkconnect-python $ sudo python -i consoletest.py 

Ready to execute commands

For connecting: mkconnect(hubId) ex: mkconnect(0) or mkconnect(1) for the second hub

 Available commands: mkconnect(hubId)
 mkstop(hubId)
 mkcontrol(deviceId, channel, powerAndDirection)

ex: mkcontrol(0, 0, 0.5) ; mkcontrol(0, 'B', -1)
 the minus sign - indicate reverse motor direction
```





Just look in [main.py](https://github.com/J0EK3R/mkconnect-python/blob/main/main.py) for current usage...

Current output in [https://wokwi.com/projects/new/micropython-pi-pico](https://wokwi.com/projects/398314618803830785)
...looks very good! :)
```
connect-telegram
rawdata: 6d 7b a7 80 80 80 80 92
crypted: 6d b6 43 cf 7e 8f 47 11 88 66 59 38 d1 7a aa 26 49 5e 13 14 15 16 17 18

stop-telegram
rawdata: 61 7b a7 80 80 80 80 80 80 9e
crypted: 6d b6 43 cf 7e 8f 47 11 84 66 59 38 d1 7a aa 34 67 4a 55 bf 15 16 17 18

C1: fullspeed forwards
rawdata: 61 7b a7 ff 80 80 80 80 80 9e
crypted: 6d b6 43 cf 7e 8f 47 11 84 66 59 47 d1 7a aa 34 67 4a ed b7 15 16 17 18

C1: halfspeed forwards
rawdata: 61 7b a7 bf 80 80 80 80 80 9e
crypted: 6d b6 43 cf 7e 8f 47 11 84 66 59 07 d1 7a aa 34 67 4a eb 70 15 16 17 18

C1: halfspeed backwards
rawdata: 61 7b a7 40 80 80 80 80 80 9e
crypted: 6d b6 43 cf 7e 8f 47 11 84 66 59 f8 d1 7a aa 34 67 4a 4e fe 15 16 17 18

C2: halfspeed backwards
rawdata: 61 7b a7 40 40 80 80 80 80 9e
crypted: 6d b6 43 cf 7e 8f 47 11 84 66 59 f8 11 7a aa 34 67 4a 3d f9 15 16 17 18
MicroPython v1.22.0 on 2023-12-27; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> 
raw REPL; CTRL-B to exit
>
```
