-2

This is the output I get after running following 2 commands.

Wc = os:cmd("curl -s -k -X GET 'http://10.210.12.158:10065/iot/get/task_id?id=1'"),
    WW = decode_json(Wc), 

OUTPUT ---

{ok,{obj,[{"status",200},
    {"data",
        [{obj,[{"id",1},
           {"task",
                <<"Turn on the bulb when the temperature is greater than 28 ">>},
           {"working_condition",1},
           {"depending_value",<<"Temperature">>},
           {"device",<<" BulbOnly">>},
           {"turning_point",28},
           {"config_id",null}]}]}]}}

I want to get these data separately.

Eg - Task = Turn on the bulb when the temperature is greater than 28

So, How can I do this?

1 Answers1

0

This the structure returned seems to return a list of tasks and each task being a proplist, you can do something like

-module(test).
-export([input/0, get_tasks/1]).

input() ->
  {ok,{obj,[{"status",200},
    {"data",
        [{obj,[{"id",1},
           {"task",
                <<"Turn on the bulb when the temperature is greater than 28 ">>},
           {"working_condition",1},
           {"depending_value",<<"Temperature">>},
           {"device",<<" BulbOnly">>},
           {"turning_point",28},
           {"config_id",null}]}]}]}}.


get_tasks({ok, {obj, [_Status, {"data", Tasks}|_Tail]}}) ->
  [ get_task_description(T) || T <- Tasks ].

get_task_description({obj, Proplist}) ->
  proplists:get_value("task", Proplist).

When running it in a shell, you would get:

1> test:get_tasks(test:input()).
[<<"Turn on the bulb when the temperature is greater than 28 ">>]
ITChap
  • 4,057
  • 1
  • 21
  • 46