Tuya Convert Walk Through – February 2019


from – The Hook Up
with minor change due to error i was getting.

Compatible device list for Tuya-Convert
https://github.com/ct-Open-Source/tuya-convert/wiki/Compatible-devices

1. Before you begin you’ll need:

  1. One of the Linux machines listed below:
    1. raspberry pi model B with the latest version of Raspbian Stretch Lite (Recommended Method).
    2. raspberry pi model B+ with a USB wifi dongle and Kali Linux.
  2. A micro SD Card for your raspberry pi (at least 2gb, 8+ recommended).
  3. A wifi device that can connect to the SSID that will be generated by the raspberry pi and eventually the flashed tuya device.  This cannot be an iOS device, android devices will work.

2, Installing the OS on raspberry pi:

  1. Download and install Etcher
  2. Plug your microSD card into your PC using a microSD adapter
  3. Start Etcher.
  4. Select the disk image you downloaded and your microSD card from the etcher interface.
  5. Press Flash and wait.
  6. Add a blank file called “ssh” to the root of the raspberry pi to enable the SSH service on raspbian.
  7. Plug the SD card into your raspberry pi, connect power and ethernet and boot it up.

3. Connecting to your raspberry pi via SSH:

  1. Download and install Putty
  2. Start Putty.
  3. Enter the IP address of your raspberry pi in the box that says “Host Name”.  I recommend using an app like Fing to find the IP address of your raspberry pi.
  4. In the “Saved Sessions” input box, name your raspberry pi connection and then press “save”.
  5. Select your new saved session.
  6. Press “Open”

4. Setting up your Pi and updating the OS

  1. In the putty window login with user “pi” and password “raspberry”
  2. Expand the file system by typing “sudo raspi-config” then selecting “Advanced Options” and then “Expand Filesystem”, select “Finish” and then select “Yes” when it asks to reboot.
  3. Reconnect via putty using your saved session and login with username “pi” and password “raspberry” again.
  4. Type “sudo apt-get update” and wait for the updates to install
  5. Type “sudo apt-get dist-upgrade” and wait for the upgrades to install
    1. You may get a prompt for permission, just type “y” and press enter.
  6. Type “sudo apt-get install network-manager” and wait for it to install.
  7. Type “sudo apt install git” and wait for it to install.

5. Setup and Install Tuya-Convert

  1. In the putty window type “git clone https://github.com/ct-Open-Source/tuya-convert” press enter and wait.
  2. Type “cd tuya-convert” and press enter.
  3. Type “./install_prereq.sh” and wait.

6. Use Tuya-Convert to install Tasmota

  1. Type “cd tuya-convert” and press enter.
  2. Type “./start_flash.sh”.
  3. Types “yes” and press enter.
  4. Connect your separate WiFi device to the “vtrust-flash” SSID that is being broadcast by your Raspberry Pi. The Password is “flashmeifyoucan”.
  5. Plug in your Tuya plug, switch, dimmer, or bulb and put into pairing mode.
    1. Different models are put into pairing mode via different methods, check the curated product pages for information for putting your device in pairing mode.  The LED should flash rapidly if done successfully.
  6. Press enter on your putty window to start the flash process and wait.
  7. Once the process completes you can type ” curl http://10.42.42.42/flash2″ to install tasmota, or look at the other options available.
  8. If it says that booting is already from userspace 2 then run following command ” curl http://10.42.42.42/flash3″
  9. after this command you should see “Device should flash http://10.42.42.1/files/thirdparty.bin and restart”

7. Setup Tasmota

  1. On your secondary device, disconnect from vtrust-flash and connect to the new SSID called “sonoff-XXXX”
  2. Open 192.168.4.1 in your browser and enter your WiFi’s SSID and password.
  3. Use Fing to find your new device on your WiFi network, it should be called “Sonoff-XXXX”
  4. Open the IP address of your new device in a browser.
  5. If using MQTT:
    1. Click “configuration”
    2. Click “configure MQTT”
    3. Enter your MQTT information
  6. If not using MQTT:
    1. Click “Console”
    2. Type “setoption3 0”
  7. To get the best compatability with Tuya products you should update to the most recent version of Tasmota.
    1. From the main tasmota screen click “Firmware Upgrade”
    2. In the top box change the URL to “http://thehackbox.org/tasmota/sonoff.bin”
    3. Press “Start Upgrade”
  8. Update the name of your device under “Configure Other” and then “Friendly Name”

7. Configure your specific device

  1. On the main tasmota screen click “Configuration”.
  2. Click “Configure Module”
  3. Consult the list of known devices to input the correct GPIO pins and chips for your device.
  4. Press “Save” and enjoy!

Posted in: Tutorials

SqlDependency.Start ( ) – Key was not present in disctionary


While using SqlDependency.Start(), I was getting “‘The given key was not present in the dictionary.'” error. I didn’t know what’s the problem but i tried stopping it before i start the new instance but no luck. After some research i found this SQL to use to clear out all queue instances so we can start new one.

DECLARE item_cursor CURSOR LOCAL FAST_FORWARD FOR
    SELECT s.conversation_handle FROM {{dbname}}.dbo.{{queuename}} s LEFT JOIN sys.conversation_endpoints e ON e.conversation_handle=s.conversation_handle WHERE e.conversation_handle IS NULL;
 -- or completely clear it below
 --SELECT s.conversation_handle FROM clients.dbo.MySBQueueName s;
OPEN item_cursor
DECLARE @conversation UNIQUEIDENTIFIER
FETCH NEXT FROM item_cursor INTO @conversation
WHILE @@FETCH_STATUS = 0 
BEGIN
    END CONVERSATION @conversation WITH CLEANUP
    FETCH NEXT FROM item_cursor INTO @conversation
END