Unable to publish advertising data for BLE in wpf application - c#

I am working on a wpf application where I need it to work as a publisher. So I want to publish some data and there will be other devices listening to this data. I am trying to send this data with advertisement and have been following This Link but I am not able to even detect this application in my iPhone app who is supposed to read this published data.
I am trying to add the data as following:
private BluetoothLEAdvertisementPublisher publisher;
this.publisher = new BluetoothLEAdvertisementPublisher();
ushort id = 0x1234;
var manufacturerDataWriter = new DataWriter();
manufacturerDataWriter.WriteUInt16(id);
var manufacturerData = new BluetoothLEManufacturerData
{
CompanyId = 0xFFFE,
Data = manufacturerDataWriter.DetachBuffer()
};
publisher.Advertisement.ManufacturerData.Add(manufacturerData);
publisher.Start();
Edit:
Do I need to create some characteristics too? I found a tutorial on MSDN about this and using smaple code I am able to send the characteristics but I am still not able to advertise my custom data to other devices.

Related

Why an installed app is not listed by Ms Graph API?

I am trying to upgrade an app which belongs to a chat. If the app is not installed, below code successfully install it:
await graph.Chats["19:7f...3#thread.v2"].InstalledApps
.Request()
.AddAsync(teamsAppInstallation);
But once the app is added, below code shows zero entries:
var installedApps = await graph.Chats["19:7f...3#thread.v2"].InstalledApps.Request().GetAsync();
I was expecting to see my app there. My target is to call Upgrade() for the app, because it should allow me to add ConversationReferences in one of the event functions (e.g. OnTurnAsync), that will allow me to send proactive message to the chat. Am I doing something wrong?
Permissions for an application are set:
TeamsAppInstallation.ReadWriteSelfForChat.All
TeamsAppInstallation.ReadWriteForUser.All
The authentication with the Graph API is done successfully, as I can create a chat, list channels etc.
https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
data:
grant_type=client_credentials&client_id={ MS_APP_ID_ENC }&client_secret={ MS_APP_PASS_ENC }&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
I was adding the app to the chat both manually and with C# request:
var teamsAppInstallation = new TeamsAppInstallation {
AdditionalData = new Dictionary<string, object>()
{
{
"teamsApp#odata.bind", "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/0c...68/"}
}
};
var installedApp = await graph.Chats["19:7f...3#thread.v2"].InstalledApps. Request().AddAsync(teamsAppInstallation);
And the app was added. It can be used in the chat.
It turned out that I've used wrong application permissions. Even though TeamsAppInstallation.ReadWriteSelfForChat.Al is listed in the docs, I needed to add TeamsAppInstallation.ReadWriteForChat.All to make it working.

Testing Slack Interactive Messages Locally

I'm currently using SlackConnector Repo https://github.com/noobot/SlackConnector. I've created a bot and it sends interactive messages to my chat. I would like to add functionality to my interactive buttons but upon clicking them i get this response. Darn – that didn’t work. Only Slack Apps can add interactive elements to messages. Manage your apps here: https://api.slack.com/apps/ So it looks like I need a request URL to get my past my current roadblock. Is there a way to Test the Interactive Message button locally?
List<SlackAttachment> attachments = new List<SlackAttachment>();
List<SlackAttachmentAction> actions = new List<SlackAttachmentAction>();
actions.Add(new SlackAttachmentAction
{
Name = "game",
Text = "chess",
Type = "button",
Value = "Chess"
});
actions.Add(new SlackAttachmentAction
{
Name = "game",
Text = "Falken's Maze",
Type = "button",
Value = "Maze"
});
actions.Add( new SlackAttachmentAction
{
Name = "game",
Text = "Thermonuclear War",
Type = "danger",
Value = "war"
});
attachments.Add(new SlackAttachment
{
Text = "Choose a game to play",
Fallback = "You are unable to choose a game",
CallbackId = "wopr_game",
ColorHex = "#3AA3E3",
Actions = actions
});
connection.Say(new BotMessage
{
ChatHub = chatHub,
Text = "Usage: !talk <user>",
Attachments = attachments
});
return Task.CompletedTask;
One thing I tried was I set the request URL to use a url generated from https://webhook.site/#/ and I still get the same response upon clicking
It looks to me like you have two problems.
You don't have a Slack app
Interactive Messages only work if you have a registered Slack app. That is why you got that error message. But you can easily create one. Just go here and click on "Create a new app". One reason you need one is that you need to tell Slack to which URL to send the request, after a user clicks a button.
Slack can't reach your local app
Slack's interactive messages will only work with apps that can be reached from the public Internet. So if you want to develop your app locally you need to open your web server to the Internet. There are many ways to do it, one secure way is to use a VPN tunnel service. One provider for this kind of service is ngrok, which is also recommended in the official Slack tutorials. I use it myself and it works great.

Retrieve Data from IMobileServiceTable in a backend application

I have a backend application which serves data for windows and android mobile applications, The Service application is hosted as a MobileService on Azure, I have a table named 'todoitem' that is associated to this Mobile service . Now I want to query this table in my controller to check if a particular id is already present in the table if not I will insert it into the table and also send a push notification to the client application. However I am able to insert the data into the table but have no clue of how to retrieve it.
This is the code for insertion
public MobileServiceClient mClient1;
public IMobileServiceTable mToDoTable;
mClient1 = new MobileServiceClient("MobileServiceName", "Key");
mToDoTable = mClient1.GetTable("todoItem");
public void Add()
{
JObject jo = new JObject();
jo.Add("Text", "Hello World");
jo.Add("Complete", false);
jo.Add("id", "123456");
jo.Add("title", "New LED");
var inserted = mToDoTable.InsertAsync(jo);
}
what I want to do now is , I want to query the todoitem table of my mobile service , for example select * from todoitem where id="1234"
Any Help is much Appreciated
Per your other question, here is the link you need: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-how-to-use-client-library/
Also, consider upgrading to Azure Mobile Apps!

How to get User Data from ListEndpointsByPlatformApplication Amazon SNS C#

I am trying to figure out how to send notifications to my ios application users using AWS Simple Notification Service.
When I look at the Application Endpoint in the web app I see:
For each registered device I am going to store our unique userId in the User Data section. Then I will want to send a push like so:
public AmazonPushProvider(AmazonProviderObject provider)
{
_client = new AmazonSimpleNotificationServiceClient(provider.AWSAccessKey, provider.AWSSecretKey);
_appARN = provider.AppARN;
}
public void SendApplePush(string apsJson, int[] userIds = null)
{
var iOSModel = _client.ListEndpointsByPlatformApplication(new ListEndpointsByPlatformApplicationRequest { PlatformApplicationArn = _appARN });
foreach (var endpoint in iOSModel.Endpoints)
{
if (endpoint.???)
}
}
The problem is ListEndpointsByPlatformApplicationRequest doesn't seem to return a User Data property. How do I get the user data property from the list of endpoints by platform application?
Once you have the platform endpoint Id you can call GetEndpointAttributes()
Which returns a response with the following info:
Gets and sets the property Attributes.
Attributes include the following:
CustomUserData -- arbitrary user data to associate with the endpoint. Amazon SNS does not use this data. The data must be in UTF-8 format and less than 2KB.
Enabled -- flag that enables/disables delivery to the endpoint. Amazon SNS will set this to false when a notification service indicates to Amazon SNS that the endpoint is invalid. Users can set it back to true, typically after updating Token.
Token -- device token, also referred to as a registration id, for an app and mobile device. This is returned from the notification service when an app and mobile device are registered with the notification service.

PushSharp:Android GCM Push Notification received without push message

I am using PushSharp library to send push notification from my application.
PushService push = new PushService();
var reg_id_d = "APA91bETd-LsqnZjA-HKrnBOY3FbEhmWchpiwuhRkiv4gUdGDuvwDRB7YURICZ131XppDAUNUBLGe_vEPkQ-JR8UaVX7Y-NCkEfastCBLIYcUoFtt5cPafeKXHywi0WGDYW33ZQqr3oy";
var project_id_d = "482885626272";
var api_key_d = "AIzaSyAbh7R5KQR3KM7W_y-yS-Ao-JNiihNz7tE"; // "AIzaSyDcKfuW77GTwA46L6sqD41YhGf2j5S8o2w";
var package_name_d = "com.get.deviceid";
push.StartGoogleCloudMessagingPushService(new GcmPushChannelSettings(project_id_d, api_key_d, package_name_d));
push.QueueNotification(NotificationFactory.AndroidGcm()
.ForDeviceRegistrationId(reg_id_d)
.WithCollapseKey("NONE")
.WithJson("{\"alert\":\"Alert Text!\",\"badge\":\"1\"}"));
I am getting notification on my device but with blank message..
I have tried with sever code available in C# to send GCM push notification, but getting same problem of having blank message.
I tried using PHP to send notification. and it is working as expected. so, I am not sure what is wrong in my above code. Can anyone please help me on this?
I tried using different code available around.. but none of those were working..
finally I tried https://stackoverflow.com/a/11651066/1005741 and it works like a charm!
I encountered the same issue, where I received an empty message. My code was a bit different and i was using different libraries: the client was wrapped with phonegap pushPlugin ,and the server code is as follows :
...
// com.google.android.gcm.server.Sender.Sender(String key)‬
gcmSender = new Sender(androidAPIkey);
// com.google.android.gcm.server.Message
Message message = new Message.Builder().addData("alert", "test message" /*notif.getAlert()*/).build();
Result result = gcmSender.sendNoRetry(message, /* device token */ notif.getToken());
nr.add(result, notif.getToken());
...
The reason why my messages where empty is due to the fact that phonegap looks for "message" , "msgcnt" or "soundname" while parsing the extras from the intent. So, this was the solution in my case :
Message message = new Message.Builder().addData("message", notif.getAlert()).build();
Hope this will help someone
Change alert to message, Please see code below for your reference:
////---------------------------
//// ANDROID GCM NOTIFICATIONS
////---------------------------
////Configure and start Android GCM
////IMPORTANT: The API KEY comes from your Google APIs Console App, under the API Access section,
//// by choosing 'Create new Server key...'
//// You must ensure the 'Google Cloud Messaging for Android' service is enabled in your APIs Console
push.RegisterGcmService(new GcmPushChannelSettings("senderid", "apikey", "com.xx.m"));
//Fluent construction of an Android GCM Notification
//IMPORTANT: For Android you MUST use your own RegistrationId here that gets generated within your Android app itself!
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("regid")
.WithCollapseKey("score_update")
.WithJson("{\"message\":\"syy!\",\"badge\":7,\"sound\":\"sound.caf\"}")
.WithTimeToLive(108)
);

Categories

Resources