Exemple #1
0
        async void Handle_Clicked(object sender, EventArgs e)
        {
            var connect = Connectivity.NetworkAccess;
            CancellationTokenSource cts;

            cts         = new CancellationTokenSource();
            status.Text = "";
            if (connect == NetworkAccess.Internet) //There is connection
            {
                try
                {
                    cts.CancelAfter(2800);
                    RESTService api_client   = new RESTService();
                    string      user_profile = await api_client.Get("https://api.thingspeak.com/channels.json?api_key=" + username_text.Text);

                    var settings = new JsonSerializerSettings
                    {
                        NullValueHandling     = NullValueHandling.Ignore,
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    };
                    if (user_profile.Contains("Authorization Required"))
                    {
                        status.TextColor = Color.Red;
                        status.Text      = "Nhập sai User API Key! Vui lòng kiểm tra lại";
                    }
                    else
                    {
                        status.TextColor   = Color.Green;
                        status.Text        = "Thành công!";
                        username_text.Text = "";
                        List <UserProfile> profile_json = JsonConvert.DeserializeObject <List <UserProfile> >(user_profile, settings);
                        await Navigation.PushAsync(new Page1(profile_json));
                    }
                }
                catch (Exception)
                {
                    status.TextColor = Color.Red;
                    status.Text      = "Không kết nối với Internet!";
                }
            }
            else
            {
                status.TextColor = Color.Red;
                status.Text      = "Không kết nối với Internet!";
            }
        }
Exemple #2
0
        async Task <ChannelFeed> ReallyGetData(string id, string api, CancellationToken ct)
        {
            RESTService api_client    = new RESTService();
            string      channel_feeds = await api_client.Get("https://api.thingspeak.com/channels/" + id + "/feeds.json?timezone=Asia%2FBangkok&api_key=" + api + "&results=2", ct);

            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            ChannelFeed feeds_json = JsonConvert.DeserializeObject <ChannelFeed>(channel_feeds, settings);

            return(feeds_json);
            //temperature.Text = feeds_json.feeds[1].field1;
            //pH.Text = feeds_json.feeds[1].field2;
            //update_time.Text = feeds_json.feeds[1].created_at.ToString("dd/MM/yyyy HH:mm tt");
        }