Variables ========= There are multiple ways to set/get variables on a data logger. These methods have evolved from early implementations to the current system, and we strive to maintain backward compatibility. However, it is recommended to use current configuration over the alternate method whenever possible. variable {action:set} --------------------- Instruct the data logger to set variables to a specified value. :guilabel:`Subscribe` ``/cc//variable`` .. admonition:: Properties - ``"action": "set"`` - ``"assignments": {}`` Object containing variable assignments - ``"variable_name":`` *(string)* value Variable access and examples: - ``"variable_name": "12.3"`` — Public variable - ``"Public.variable_name": "12.3"`` — Public variable with explicit scope - ``"variable_name(2)": "2.013"`` — Array element of a public variable - ``"StructureName.variable_name": "12.3"`` — Variable inside a structure - ``"StructureName.variable_name(2)": "12.3"`` — Array element of a variable inside a structure - ``"trigger_event": "true"`` - Boolean variables .. note:: The JSON keys and the values must be type ``string``. The string values will be converted to the appropriate types by the data logger. **Example Command** :guilabel:`Subscribe` ``cs/v2/cc/ABCD-EFGH-1234/variable`` .. code-block:: json { "action": "set", "assignments": { "bale_count": "20", "field_name": "north_40", "farmall.pto_engaged": "False", "farmall.engine_rpm": "1780.0" } } **Response** :guilabel:`Publish` ``cs/v2/cr/ABCD-EFGH-1234/variable`` .. code-block:: json { "success": "variables set" } VariableSet ----------- Alias for ``variable {action:set}``. Functionally identical, but the action is encoded in the topic name instead of an ``"action"`` key in the payload. :guilabel:`Subscribe` ``/cc//VariableSet`` .. admonition:: Properties - ``"assignments": {}`` Object containing variable assignments - ``"variable_name":`` *(string)* value See *variable {action:set}* above for variable access examples (public, structure, array element, boolean, etc.). **Example Command** :guilabel:`Subscribe` ``cs/v2/cc/ABCD-EFGH-1234/VariableSet`` .. code-block:: json { "assignments": { "acres_harvested": "151", "i_did_a_thing": "False" } } **Response** :guilabel:`Publish` ``cs/v2/cr/ABCD-EFGH-1234/VariableSet`` .. code-block:: json { "success": "Variables set" } setVar ------------------ Alternate method to set a single variable :guilabel:`Subscribe` ``/cc//setVar`` .. admonition:: Properties - ``"name":`` *(string)* variable name - ``"value":`` *(string)* variable value **Example Command** :guilabel:`Subscribe` ``cs/v2/cc/ABCD-EFGH-1234/setVar`` .. code-block:: json { "name": "bale_count", "value": "25" } **Response** :guilabel:`Publish` ``cs/v2/cr/ABCD-EFGH-1234/setVar`` .. code-block:: json { "success":"Set variable succeeded" } variable {action:get} --------------------- Request the data logger to retrieve the current value of one or more variables. :guilabel:`Subscribe` ``/cc//variable`` .. admonition:: Properties - ``"action": "get"`` - ``"names": []`` Array containing variable names to retrieve. When empty or omitted, all accessible public variables are requested. Variable access and examples: - ``"names": []`` — Get all public variables - ``"names": ["battery_voltage"]`` — Single public variable - ``"names": ["battery_voltage", "panel_temperature"]`` — Multiple public variables - ``"names": ["data_array(1)", "data_array(2)"]`` — Individual array elements (Note: you **cannot** request the entire array as ``"data_array()"``; each element must be explicitly listed.) - ``"names": ["structure_1.member_array(1)", "structure_1.member_array(2)"]`` — Structure members - ``"names": ["structure_2.member_trigger"]`` — Structure member variable **Example Command: All Variables** :guilabel:`Subscribe` ``cs/v2/cc/ABCD-EFGH-1234/variable`` .. code-block:: json { "action": "get", "names" : [ ] } **Example Command: Specified List** :guilabel:`Subscribe` ``cs/v2/cc/ABCD-EFGH-1234/variable`` .. code-block:: json { "action": "get", "names": [ "buckwheat_storage_level", "barly_storage_level", "corn_storage_level", "lamborghini_R(1).location", "lamborghini_R(1).engine_rpm", "lamborghini_R(1).fuel_level", "lamborghini_R(1).pto_engaged", "lamborghini_R(1).tire_pressure(1)", "lamborghini_R(1).tire_pressure(2)", "lamborghini_R(1).tire_pressure(3)", "lamborghini_R(1).tire_pressure(4)" ] } **Response** The response provides an object for each requested variable. Each object includes both the variable's current value and its data type. - ``"t"`` — *(string)* The variable's data type (e.g., ``"float"``, ``"int"``, ``"string"``, ``"boolean"``). - ``"v"`` — *(string)* The current value of the variable. :guilabel:`Publish` ``cs/v2/cr/ABCD-EFGH-1234/variable`` .. code-block:: json { "buckwheat_storage_level": { "t": "float", "v": "10.1" }, "barly_storage_level": { "t": "float", "v": "10.2" }, "corn_storage_level": { "t": "float", "v": "10.3" }, "lamborghini_R(1).location": { "t": "string", "v": "South 40" }, "lamborghini_R(1).engine_rpm": { "t": "int", "v": "1100" }, "lamborghini_R(1).fuel_level": { "t": "float", "v": "96.31922" }, "lamborghini_R(1).pto_engaged": { "t": "boolean", "v": "True" }, "lamborghini_R(1).tire_pressure(1)": { "t": "float", "v": "32.1" }, "lamborghini_R(1).tire_pressure(2)": { "t": "float", "v": "32.2" }, "lamborghini_R(1).tire_pressure(3)": { "t": "float", "v": "33.1" }, "lamborghini_R(1).tire_pressure(4)": { "t": "float", "v": "33.2" } } VariableGet ----------- Alias for ``variable {action:get}``. Functionally identical, but the action is encoded in the topic name instead of an ``"action"`` key in the payload. :guilabel:`Subscribe` ``/cc//VariableGet`` .. admonition:: Properties - ``"names": []`` Array containing variable names to retrieve. When empty or omitted, all accessible public variables are requested. See *Get Variable* above for variable access examples (public, array element, structure member, etc.). **Example Command: Specified List** :guilabel:`Subscribe` ``cs/v2/cc/ABCD-EFGH-1234/VariableGet`` .. code-block:: json { "names": [ "buckwheat_storage_level", "barly_storage_level", "corn_storage_level", "lamborghini_R(1).location", "lamborghini_R(1).engine_rpm", "lamborghini_R(1).fuel_level", "lamborghini_R(1).pto_engaged", "lamborghini_R(1).tire_pressure(1)", "lamborghini_R(1).tire_pressure(2)", "lamborghini_R(1).tire_pressure(3)", "lamborghini_R(1).tire_pressure(4)" ] } **Example Command: All Variables** :guilabel:`Subscribe` ``cs/v2/cc/ABCD-EFGH-1234/VariableGet`` .. code-block:: json { "names" : [ ] } **Response** The response format is identical to *Get Variable* — an object per requested variable containing its data type (``"t"``) and current value (``"v"``). :guilabel:`Publish` ``cs/v2/cr/ABCD-EFGH-1234/VariableGet`` GetVar ------------------ Method to get a single variable :guilabel:`Subscribe` ``/cc//getVar`` .. admonition:: Properties - ``"name":`` *(string)* variable name **Example Command** .. code-block:: json { "name": "bale_count" } **Response** :guilabel:`Publish` ``cs/v2/cr/ABCD-EFGH-1234/getVar`` .. code-block:: json { "name":"bale_count", "value":"56" } List Variables -------------------------- List variables and their types from a table. .. important:: Other than the Public Table, all Data Tables must include the ``MQTTPublishTable()`` CRBasic instruction. Tables such as a Structure, Status, CPIStatus, or similar system tables cannot expose their variable names using this method. :guilabel:`Subscribe` ``/cc//listVar`` .. admonition:: Properties - ``"table":`` - ``null`` or ``"public"`` will return the public variables **Example Command** :guilabel:`Subscribe` ``cs/v2/cc/ABCD-EFGH-1234/listVar`` .. code-block:: json { "table" : "Public" } :guilabel:`Publish` ``cs/v2/cr/ABCD-EFGH-1234/listVar`` .. code-block:: json { "juice_level": "float", "logger_temp": "float", "extreme_temperature": "boolean", "message": "string" }