Welcome, Guest
Username: Password: Remember me

TOPIC: Send Push Notification Over PushBullet

Send Push Notification Over PushBullet 1 year 2 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
	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);
  } catch (Exception ex) {

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 2 months ago by lennysh. Reason: Cleaned up the code a bit...
The administrator has disabled public write access.
Time to create page: 0.123 seconds
Powered by Kunena Forum