示例#1
0
        public async void Line_Send(ClassDATA a, string info)
        {
            //string al = null;
            //if (info.Status == "0")
            //{
            //    al = "ระดับน้ำไกลผิวดิน";
            //}
            //else if (info.Status == "1")
            //{
            //    al = "ระดับน้ำไกลผิวดินมาก";
            //}
            //else if (info.Status == "2")
            //{
            //    al = "ระดับน้ำใกล้ผิวดินมาก";
            //}
            //else if (info.Status == "3")
            //{
            //    al = "ระดับน้ำใกล้ผิวดินมาก";
            //}
            //string mes = "รหัสบ่อ " + info.StationID + " ระดับน้ำ " + info.TagValue + " เวลา " + info.TimeStamp + " แจ้งเตือน " + al
            string mes    = "123";
            var    values = new Dictionary <string, string>
            {
                { "message", mes }
            };

            var content = new FormUrlEncodedContent(values);

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//ACCEPT header
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "NZ5cLxBIYUQFlILxlOsNyr9elSsRmblqPg5arAZRZ6R");
            var response = await client.PostAsync("https://notify-api.line.me/api/notify", content);

            var responseString = await response.Content.ReadAsStringAsync();
        }
示例#2
0
 private void InsertDataEvent(ClassDATA a, string b, float c)
 {
     using (db = new CatLoraPostContext())
     {
         using (var tran = db.Database.BeginTransaction())
         {
             try
             {
                 var query = new Collecteddata()
                 {
                     //Timestamp = a.DevEUI_uplink.Time,
                     Timestamp     = DateTime.Now,
                     DeviceAddress = a.DevEUI_uplink.DevAddr,
                     DevEui        = a.DevEUI_uplink.DevEUI,
                     SensorId      = b,
                     ValueSensor   = c,
                     Fport         = float.Parse(a.DevEUI_uplink.FPort.Replace(" ", "")),
                     FcntUp        = float.Parse(a.DevEUI_uplink.FCntUp.Replace(" ", "")),
                     FcntDw        = float.Parse(a.DevEUI_uplink.FCntDn.Replace(" ", "")),
                     Rssi          = float.Parse(a.DevEUI_uplink.LrrRSSI.Replace(" ", "")),
                     Snr           = float.Parse(a.DevEUI_uplink.LrrSNR.Replace(" ", "")),
                     SubBand       = a.DevEUI_uplink.SubBand,
                     Channel       = a.DevEUI_uplink.Channel,
                     Lrr           = a.DevEUI_uplink.Lrrid,
                     Timereceive   = DateTime.Now
                                     // Ack = a.DevEUI_uplink.Time,
                                     //DeliveryStatus = a.DevEUI_uplink.Time,
                                     //Rx1 = a.DevEUI_uplink.Time,
                                     //Rx2 = a.DevEUI_uplink.Time,
                                     // Beacon = a.DevEUI_uplink.ba
                 };
                 db.Collecteddata.Add(query);
                 db.SaveChanges();
                 tran.Commit();
                 this.Log("Insert Data Commit");
             }
             catch (Exception ex)
             {
                 tran.Rollback();
                 this.Log(ex.Message);
             }
         }
     }
 }
示例#3
0
        public void Post([FromBody] ClassDATA value)
        {
            this.Log(value);
            dynamic Pay = DecodePayload(value.DevEUI_uplink.payload_hex);


            switch (value.DevEUI_uplink.FPort)
            {
            case "1":     // command
                DateTime dt       = DateTime.Now;
                string   hexValue = ((long)((dt - new DateTime(1970, 1, 1)).TotalMilliseconds)).ToString("X");

                if (hexValue.Length % 2 != 0)
                {
                    hexValue = "0" + hexValue;
                }

                Uplink(value.DevEUI_uplink.DevEUI, hexValue, value.DevEUI_uplink.FPort);
                break;

            case "2":     // event
                foreach (KeyValuePair <string, object> kvp in ((IDictionary <string, object>)Pay))
                {
                    InsertDataEvent(value, kvp.Key, float.Parse(kvp.Value.ToString()));
                }
                //Line_Send("");
                break;

            case "3":     // data
                foreach (KeyValuePair <string, object> kvp in ((IDictionary <string, object>)Pay))
                {
                    InsertData(value, kvp.Key, float.Parse(kvp.Value.ToString()));
                }

                break;
            }
        }