public static void SendKannel(string phoneNumber, string message) { //This is the swedish HOMEGROWN SMS sending mechanisma String encodedMessage = HttpUtility.UrlEncode(message, Credential.Encoding); String encodedPhone = NormalizePhoneNumber(phoneNumber, Credential.Encoding); String username = Credential.Login; String password = Credential.Password; Encoding enc = Credential.Encoding; String url = "https://nurse.sanitarium.se/sms/sendsms"; String call_string; String result; call_string = url + "?username="******"&password="******"&to=" + encodedPhone + "&text=" + encodedMessage + "&charset=latin1"; result = HTTPSender.Send(call_string, enc); if (result != "0: Accepted for delivery") { throw new Exception("Error on SMS transmit: phone number " + phoneNumber + ", error code " + result); } }
public static bool CheckServiceStatus() { switch (Credential.ServiceName) { case "SwedishSms": return(true); //cant test this case "SwedishKannel": { String username = Credential.Login; String password = Credential.Password; Encoding enc = Credential.Encoding; String url = "https://nurse.sanitarium.se/kannel/status"; String result; HttpWebResponse responseOut = null; try { result = HTTPSender.Send(url, enc, 1500, out responseOut); if (((int)responseOut.StatusCode).ToString().StartsWith("2")) { return(true); } return(false); } catch (Exception) { return(false); } } default: throw new Exception("Error on SMS transmit. Unknown SMS service: " + Credential.ServiceName); } }
private void PostUpdates() { // Getting values from preferences string deviceInfo = Android.OS.Build.Model; // Log Log.Debug(TAG, "Foreground updating"); Log.Debug(TAG, "Device info: " + deviceInfo); Log.Debug(TAG, "Post url: " + AppConfig.PostUrl); // Getting lat/lon Location location = LocationServices.FusedLocationApi.GetLastLocation(apiClient); double lat = location.Latitude; double lon = location.Longitude; // Getting the resource detail ResourceDetail det = HTTPSender.createResourceDetail(AppConfig.UserID, AppConfig.Agency); List <EventDetails> detailsList = new List <EventDetails>(); detailsList.Add(det); if (sensorDetailMap.Count > 0) { Log.Debug(TAG, "Adding Sensor Details"); detailsList.AddRange(sensorDetailMap.Values.ToList()); } HTTPSender.sendUpdate(lat, lon, AppConfig.UserID, AppConfig.Agency, AppConfig.PostUrl, AppConfig.SelectedResource, detailsList); }
/// <summary> /// Retrieves data and sets heart rate for hexoskin, and returns TRUE if the data was retrieved successfully. /// </summary> /// <returns><c>true</c>, if get data was caned, <c>false</c> otherwise.</returns> public bool CanGetData() { if (!String.IsNullOrEmpty(_watchTowerSettings.HexoskinID)) { string hexoskinID = _watchTowerSettings.HexoskinID; // synchronous call string sHexoskinJson = HTTPSender.getHexoskinDataSynchronous(BASE_URL, hexoskinID); ParseHexoskinJson(sHexoskinJson); } return(bConnectedToData); }
async Task GetHexoskinDataAsync() { if (!String.IsNullOrEmpty(_watchTowerSettings.HexoskinID)) { string hexoskinID = _watchTowerSettings.HexoskinID; Task <String> hexoskinTask = HTTPSender.getMessageWithResponse(BASE_URL, hexoskinID); string sHexoskinJson = await hexoskinTask; ParseHexoskinJson(sHexoskinJson); } else { bConnectedToData = false; } }
void PostLocation() { //don't post location unless it's been set if (_lastLocation.LocationUpdated) { //Console.WriteLine($"posting location for user {_watchTowerSettings.UserID}. Latitude: {_lastLocation.Latitude}; Longitude: {_lastLocation.Longitude}"); HTTPSender.SendLocation(_lastLocation.Latitude, _lastLocation.Longitude, _watchTowerSettings.ServerUrl, _watchTowerSettings.UserID, _watchTowerSettings.Agency, _watchTowerSettings.ResourceType, SingletonManager.BluetoothSensorManager.GetAllSensorDetails()); _lastLocation.TimeLastPosted = DateTime.Now; _lastLocation.bLocationWasPosted = true; _lastLocation.LatitudeLastPosted = _lastLocation.Latitude; _lastLocation.LongitudeLastPosted = _lastLocation.Longitude; //SingletonManager.BluetoothSensorManager.SendAllDataToServer(); } }
internal static void SendMoSMS(string phone, string message) { // This is the SWEDISH sms transmission mechanism. // Sätt användarnamn, lösenord och URL till MO-SMS. String mosms_username = Credential.Login; String mosms_password = Credential.Password; Encoding enc = Credential.Encoding; String mosms_url = "http://www.mosms.com/se/sms-send.php"; String call_string; String result; // Sätt mottagarens telefonnummer String mosms_number = phone; // Sätt vilken typ av SMS som skall skickas. String mosms_type = "text"; String encodedMessage = HttpUtility.UrlEncode(message, Credential.Encoding); // Sätt SMS-meddelandet som skall skickas String mosms_data = encodedMessage; mosms_data = HttpUtility.UrlEncode(mosms_data, enc); call_string = mosms_url + "?username="******"&password="******"&nr=" + mosms_number + "&type=" + mosms_type + "&data=" + mosms_data; result = HTTPSender.Send(call_string, enc); result = HttpUtility.UrlDecode(result, enc); if (result != "0") { throw new Exception("Error on SMS transmit: phone number " + phone + ", error code " + result); } }
public void hexoSkinConnect(BluetoothDevice dev) { DateTime lastChange = DateTime.MinValue; System.Timers.Timer t = new System.Timers.Timer(AppUtil.HEXOSKIN_INTERVAL); System.Timers.Timer timeOut = new System.Timers.Timer(AppUtil.HEXOSKIN_CONNECT_TIMEOUT); timeOut.AutoReset = true; timeOut.Elapsed += delegate { // Checking if HexoSkin Timed out TimeSpan duration = DateTime.Now - lastChange; if (duration.TotalMilliseconds > AppUtil.HEXOSKIN_CONNECT_TIMEOUT) { timeOut.Enabled = false; t.Enabled = false; // Send disconnect notice sendStateUpdate(dev.Address, false, "Hexoskin stopped reporting data"); } timeOut.Interval = AppUtil.SENSOR_CONNECT_TIMEOUT; }; t.AutoReset = true; t.Elapsed += async delegate { timeOut.Enabled = true; Log.Debug(LOG_TAG, "Getting hexoskin reading"); try { string data = await HTTPSender.getMessage("https://s3.amazonaws.com/pscloud-watchtower/", dev.Name); // If we got valid data if (!string.IsNullOrWhiteSpace(data)) { if (lastChange == DateTime.MinValue) { // First time we read data. sendStateUpdate(dev.Address, true, "Hexoskin started reporting data"); } lastChange = DateTime.Now; // Sending data to SensorHandler Dictionary <string, string> deviceDetails = new Dictionary <string, string>(); deviceDetails.Add("device_name", dev.Name); // Get the sensor handler SensorHandler sh = new SensorHandler(deviceDetails, AppConfig.UserID); byte[] dataArr = Encoding.UTF8.GetBytes(data); sh.updateData(dataArr); string xmlDetail = sh.xmlDetail; Log.Debug(LOG_TAG, xmlDetail); // Notifying Intent message = new Intent(AppUtil.SENSOR_READING_UPDATE_ACTION); Bundle intentBundle = new Bundle(); intentBundle.PutString(AppUtil.ADDRESS_KEY, dev.Address); intentBundle.PutString(AppUtil.DETAIL_KEY, xmlDetail); // Get Time last reading was taken Dictionary <string, string> dataJson = JsonConvert.DeserializeObject <Dictionary <string, string> >(data); double epochValue; if (double.TryParse(dataJson["timestamp"], out epochValue)) { epochValue = epochValue / 256; DateTime hexoSkinRead = AppUtil.FromUnixTime((long)epochValue); hexoSkinRead = DateTime.SpecifyKind(hexoSkinRead, DateTimeKind.Utc); hexoSkinRead = hexoSkinRead.ToLocalTime(); intentBundle.PutString(AppUtil.TIME_KEY, hexoSkinRead.ToString() ); } message.PutExtras(intentBundle); SendBroadcast(message); } } catch (Exception ex) { Log.Debug(LOG_TAG, "Getting Hexoskin data failed"); } }; t.Enabled = true; }