-
Notifications
You must be signed in to change notification settings - Fork 4
90. tuyaDAEMON toolkit
Adding a new smart device to tuyaDAEMON is simple:
-
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). -
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.
-
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.
- Find a 300x300 jpeg image of your device. Name the file
-
STEP: Add
device data
anddp 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 foralldevices
(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.
-
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.
- Refine your
device
anddp
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.
- STEP: Time to update the
global.alldevices
structure in your tuyaDAMON CORE. Copy and paste the JSON from the toolkit page toalldevices
node in tuyadDAEMON CORE. Update it with username and id.
-
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). -
STEP: The last tool creates a zip file to store or share your device: it contains the information
pdf
file, a JSONglobal.alldevices
fragment, asql
file to update the DB, and the image file of the device.
- 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' inglobal.alldevices
, you have a WARNING. For test purposes, you can temporarily delete/rename all device capabilities inglobal.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
andOUT data process
nodes [since ver. 2.2: add to CORE.'*ENCODE/DECODE user libraryr' node] , and add the newfieldtype
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.
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.
note: the tables odt_reports
, odt_queries
are used by odtReportSQL
library, the tables deviceinfos
, devicedpoints
contain devices and dp data.