Skip to content

90. tuyaDAEMON toolkit

Marco Sillano edited this page Jun 28, 2023 · 3 revisions

tuyaDAEMON toolkit

Adding a new smart device to tuyaDAEMON is simple:

  1. You need to add some nodes to tuyaDEAMON CORE ('tuya-smart-device', 'spy status' and 'connect') and update other nodes ('real device selector', 'catch device and LAN errors') (see Add a new smart device).

  2. You need to update the global.alldevice structure (see here for more) with the capabilities of the new device, to use it in production without problems.

This last point can be very long: it is not easy to find all the dp of a new smart device and doing a lot of tests using ad hoc nodes can be tedious. Editing the large global.alldevices JSON in a little window is also not easy.

Here using the tuyaDEAMON toolkit is really productive, reducing the effort of many tasks. It uses a MySQL database to store all information about the device and creates some useful artifacts to help the user in the device installation process.

toolkit

  1. STEP A 'real' or 'virtual' device MUST work in smartLife app, and you MUST know the device ID and the device Key. A 'mirror' or 'fake' device is user-defined.

    • Find a 300x300 jpeg image of your device. Name the file <device-name>.jpg and put it on /pics dir. Toolkit will use it.
  2. STEP: Add device data and dp descriptions to the DB. This Toolkit offers you a simple but functional CRUD interface. You can use this starter device definition with default values to create a generic first snippet for alldevices (see step 5). notes:

    • Do not use the '"' (double quotation mark) char. In some fields, unallowed chars are replaced automatically.
    • For multiple URLs, use ',' (comma) as separator, without spaces.
  3. STEP: Test the device using the ad hoc page with wired 'GET', 'SET', 'MULTIPLE' and 'SCHEMA' commands for a device and all defined dp. Fill in the right values for the SET test (Usually, to use the GET value is ok).Also you can do all GET/SET tests automatically.

test screen

  • Refine your device and dp capability definitions (STEP1) and test the device again (STEP2): in 'AUTO' mode all buttons should turn green.
  • To test the REFRESH capability, you must add in core a 'REFRESH' node to device.
  1. STEP: Time to update the global.alldevices structure in your tuyaDAMON CORE. Copy and paste the JSON from the toolkit page to alldevices node in tuyadDAEMON CORE. Update it with username and id.

test screen

  1. STEP: Everything works fine! You can now build a documentation page for your device, for future reference. Open the <device-name>.odt file in the /devicedata directory using OpenOffice4, and export it as <device-name>.pdf in the same directory (see devices dir).

  2. STEP: The last tool creates a zip file to store or share your device: it contains the information pdf file, a JSON global.alldevices fragment, a sql file to update the DB, and the image file of the device.

notes

  • The test page (STEP3) is build using the Data Point capabilities defined in DB, but tuyaDEAMON uses the definitions found in global.alldevices. So if you do a 'GET' on a Data Point defined 'WO' in global.alldevices, you have a WARNING. For test purposes, you can temporarily delete/rename all device capabilities in global.alldevices, because the defaults are 'ALL' (device) and 'RW' (data points).
  • The 'capability' of a dp controls the external access by SET, GET. This 'capability' can change also according to your objectives: for example, the same 'dp' can be defined 'RW' for a test, 'WW' in production, and 'TRG' if it is used internally by tuyaDEAMON.
  • If you need new decode/encode functions for your data, add them to format command and OUT data process nodes [since ver. 2.2: add to CORE.'*ENCODE/DECODE user libraryr' node] , and add the new fieldtype in the DB 'lookupdecode' table, using phpmyadmin.
  • You can customize the JSON output format by changing two constants in the htdocs\tuyadaemontoolkit\makeJSON.php file that control comments: COMMENTS_IN_ALLDEVICES, which inserts the 'note01' and 'note02' fields for a device, and VALUES_IN_ALLDEVICES, which inserts the 'value' field for all dPs. The default is "false" to minimize the output.
  • You can edit and customize the template used in STEP 5, but pay attention to what is indicated in template issue.

version 2.0

Added test for the REFRESH operation. Look at the debug pad for the device response, with the 'OUT trace' enabled, to see if the device accepts a REFRESH. This test requires the presence of 'REFRESH' node for the device under test.


Toolkit uses crudClass4.php for the simple CRUD interface and odtReportSQL.php to create the OpenOffice document. It also uses the PclZip library to create the final zip file.

dB tables in dataBase tuyathome:

note: the tables odt_reports, odt_queries are used by odtReportSQL library, the tables deviceinfos, devicedpoints contain devices and dp data.

Clone this wiki locally