Welcome, Guest
Username: Password: Remember me

TOPIC: Send Push Notification Over PushBullet

Send Push Notification Over PushBullet 1 year 3 months ago #2509

  • lennysh
  • lennysh's Avatar
  • Offline
  • New Member
  • Eat. Sleep. Drink. IT.
  • Posts: 7
  • Karma: 0
Figured I'd post my code on how to send push notifications from the EasyIoT Server to your devices using the free PushBullet service...

(I also posted code on this topic on doing the same thing with PushOver instead...)

Here's the code... Enjoy!
public void PushBulletSend(string type, string title, string message)
{
  try {
  	string apikey = "Put Your Special API Key Right Here";
    
	//Set the headers to accept json and send form data 
    string authEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(apikey + ":"));
	System.Net.WebClient wc = new System.Net.WebClient();
    wc.Headers[System.Net.HttpRequestHeader.UserAgent] = "EasyIoT.Server";
    wc.Headers[System.Net.HttpRequestHeader.Authorization] = string.Format("Basic {0}", authEncoded);
	wc.Headers[System.Net.HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
	wc.Headers[System.Net.HttpRequestHeader.Accept] = "application/json";
	
	//First parameters to send
	string parameters = String.Format("type={0}", type);

	//Send different parameters depending on type to push
	//https://api.pushbullet.com/api
	if (type == "note") {
	  parameters += String.Format("&title={0}&body={1}", Uri.EscapeUriString(title), Uri.EscapeUriString(message));
	} else if (type == "link") {
	  parameters += String.Format("&title={0}&url={1}", Uri.EscapeUriString(title), Uri.EscapeUriString(message));
	} else if (type == "address") {
	  parameters += String.Format("&name={0}&address={1}", Uri.EscapeUriString(title), Uri.EscapeUriString(message));
	} else if (type == "list") {
	  parameters += String.Format("&title={0}", Uri.EscapeUriString(title));
      string[] items = message.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
      foreach (string item in items) {
        parameters += String.Format("&items={0}", Uri.EscapeUriString(item));
      }
	}

    System.Net.ServicePointManager.ServerCertificateValidationCallback =new System.Net.Security.RemoteCertificateValidationCallback(delegate { return true; });

	//Send the parameters and get the result
	string result = wc.UploadString("https://api.pushbullet.com/v2/pushes", parameters);
    Console.WriteLine(result);
    
  } catch (Exception ex) {
	Console.WriteLine(ex.Message);
  }
}

And here's how I'm using the code in an Automation program:
PushBulletSend("note", "EasyIoT Message", "Test message using my PushBullet Code!");
Last Edit: 1 year 3 months ago by lennysh. Reason: Cleaned up the code a bit...
The administrator has disabled public write access.

Send Push Notification Over PushBullet 1 day 4 hours ago #3722

  • igmsoft
  • igmsoft's Avatar
  • Offline
  • New Member
  • Posts: 1
  • Karma: 0
Hello, I'm new to this, can you be more specific, where the code is placed and how it would look notification program that vapors exceeding the set temperature?
Thanks,
The administrator has disabled public write access.
Time to create page: 0.284 seconds
Powered by Kunena Forum