Send push notification via Cortana - c#

I'm writing a program in C# to get the system's public IP and inform the user of the new one if it changes. The problem is I have two ways of informing the user: Email or Cortana. For the first one (Email) I need an anonymous email sender that I don't have, or ask the user to provide his/her credentials (most people won't). Second way (Cortana): Let's say I have the program installed on my home PC and I have Cortana enabled on Windows 10 and a Windows Phone with Cortana. If my home PC's public IP address changed, Cortana will show a notification on my phone including my new IP address.
I saw an API on github (that can't do this) and Cortana for developers. I thought "actions" can do the job but after reading the descriptions I'm somehow sure that it can't.
How can I do that?
What I did:
I wrote a little program for Windows 10
https://www.microsoft.com/en-us/store/apps/remotecmd/9nblggh4vr31
and the server side app
http://naryhd.com/RemoteCMDServerBETA.zip
This app lets you have your PC's cmd on your windows phone. (locally)
Now I want to add "access from internet" to it, (I did that, but for security reasons I disabled it, now I got a more secure solution for it)
There are 3 things that I do for accessing it from the internet
Command 1:
netsh http add urlacl url=http://ip:port/ user=everyone
Command 2:
netsh advfirewall firewall add rule name=\"RemoteCMDserver2\" dir=in protocol=tcp localport=port profile=public | private remoteip=localsubnet action=allow
Forwarding that port:
var discoverer = new NatDiscoverer();
var cts = new System.Threading.CancellationTokenSource(10000);
var device = await discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts);
await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, "REMOTECMD"));
I used open.nat from nuget to do port forwarding.
I use this code to get the PC's public IP:
var discoverer = new NatDiscoverer();
var device = await discoverer.DiscoverDeviceAsync();
var ip = await device.GetExternalIPAsync();
I save that IP in a text file, and repeat checking it every minute, and if it changes it will save that IP and send that IP to the user (currently via email) but I would like to send it with Cortana.

You can't do that with Cortana, as of right now. You can have a App, on the Phone, that displays a push Notification in the Action Center or on a Live Tile.
Here is some hopefully useful links:
Toast Notification and Action Center Overview for Windows 10
Inside Windows Platform | How to Add Push Notifications to Your App

Related

iOS push notifications with Xamarin.iOS not showing up consistently

We've been trying to get iOS push notifications to work but it's been very inconsistent. We've created a test project with as little code as possible just to get notifications to work.
We decided to test with alert notifications since we couldn't even get that to work consistently.
This is what we've been doing in the FinishedLaunching method of the AppDelegate:
UNUserNotificationCenter.Current.Delegate = this;
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
{
LogInformation("RequestAuthorization", $"Granted: {granted}, Error: {error}");
if (granted)
InvokeOnMainThread(UIApplication.SharedApplication.RegisterForRemoteNotifications);
});
And we log the registration token of the device in the console so that we can use that to send notifications.
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
LogInformation("RegisteredForRemoteNotifications", "init");
var token = ExtractToken(deviceToken);
LogInformation("RegisteredForRemoteNotifications", token);
}
That's basically all we have in the app for now.
We use the notification token in a test app to send notifications to that specific device.
These are our results:
Use case 1
Restart device
Send notification to device
Result: Notification shows up and all new notifications keep working too.
Use case 2
Restart device
Send notification to device
Result: Notification is not shown and no matter how often you send the notification, it won't be shown.
Use case 3
Restart device
Send notification to device
Notification is not shown.
Restart device
Result: Notification shows up and all new notifications keep working too.
Use case 4
Restart device
Start application once
Put app in background, or close it completely
Send notification to device
Result: Notification is shown and all new notifications keep working too.
So it looks like that once we receive 1 notification, all future notifications will work too up until the device is restarted.
After restarting the device, it's basically a coinflip: You either are lucky and receive a notification and all future notifications. Or you don't receive anything at all.
We want to receive notifications consistently and are trying to figure out how to get this done and we hope someone can shed some light into this matter.
Thanks in advance.
Notes
We're using a 6th gen iPad with iOS 13.5.1
iPad is WiFi only
We've got a stable WiFi and internet connection

Cannot get Mosquitto to Allow Connection from Outside Local Network

I have Linux Ubuntu 18.04 laptop, and I installed the Mosquitto MQTT broker there. On my Windows 10 laptop, I am running a C# application written in Visual Studio 2013 that uses the M2Mqtt Libraries.
If I connect via the localhost, everything is fine. I start up the Mosquitto server, connect via the C# application, subscribe to a topic, and then can send messages back and forth all day long.
But when I try to connect through the internet address, I consistently get a uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException:
"No connection could be made because the target machine actively
refused it 95.XXX.XXX.134:1883" error. (The address there is what I got via "WhatsmyIP")
Here's what I have done so far:
First, I went to my router, which is a TP-LINK AC1200. I set the port to forward to the local IP address of the Linux box.
Then I went to my Linux box and used ufw to enable port 1833 and enable the firewall
From there I have tried everything I can think of -- I've run Mosquitto with the port declared at the command line, I have changed the conf file to say:
Listener 1883 0.0.0.0
and
Listener 1883 192.168.0.144
I have removed the port assignment and listener assignment entirely (since that is its default anyway) and always I get the same result.
I downloaded 2 different utilities -- one on an android phone and one is an app available from Windows store, and I cannot connect with either of them, either. The Android phone simply will not connect (it is not on the same network so localhost is not an option) and the other app will connect locally, but not when I change to the internet address.
I get the sense I'm just missing one small thing, but I can't figure out what it is. There are other stackoverflow questions that show the same error, but they don't help me.
If it matters, the actual C# code that is being run is:
try
{
System.Security.Cryptography.X509Certificates.X509Certificate caCert = null;
Boolean useSecureProtocol = false;
int OpenPort = 1883;
// external IP address
String PublicIPAddress = "95.XXX.XXX.134";
// local IP address
String LocalIPAddress = "192.168.0.144";
System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(PublicIPAddress);
client = new MqttClient(ipaddress, OpenPort, useSecureProtocol, caCert, MqttSslProtocols.TLSv1_0);
// certificate and Protocol are irrelevant because security set to false??
}
catch (System.Net.Sockets.SocketException SException )
{
string SEX = SException.Message;
}
* * *
try
{
Byte retVal = client.Connect(ClientId);
}
catch (uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException ex)
{
string m = ex.Message;
}
Config File: conf.d (which I run explicitly with the -C option)
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
#
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /home/mark_admin/mosquitto.log
include_dir /etc/mosquitto/conf.d
As I said, I have changed it and tried many things:
Listener 1883 192.168.0.144
Listener 1883 0.0.0.0
Listener 1883
And none of the above. Just left it blank. None of them worked.
I'm posting this as an answer so I can give more detail in case anyone stumbles upon this in the future.
Setting up the MOSQUITTO MQTT Server in Ubuntu 18.04 is actually not hard, but the steps are important.
Step 1: Install Mosquitto Software
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
sudo apt-get install mosquitto
Step 2: Open Port 1883 and start firewall
sudo ufw allow 1883
sudo ufw enable
Step 3: Verify Mosquitto is not already running
pgrep mosquitto
[Note, if any number shows, that is the PID of an already running Mosquitto. You can just kill it. Also, you can try: sudo service mosquitto stop]
Step 4: Start Mosquitto with verbose option
mosquitto -v
[Note: This starts Mosquitto without using any config file. It echos connection and status information to the screen. Easiest for quick debugging.]
Step 5: Check connectivity using local host
Go to your client machine (in my case a Windows 10 laptop) and run the MQTT client, connecting to the local address of the Linux Mosquitto server (in my case 192.168.0.144). You should be able to connect. In fact, you can do this step before you even open the firewall, since this is all on the local network, the firewall rules are irrelevant at this point. Until next step which is...
Step 6: Check Connectivity using web tool
use either: www.yougetsignal.com/tools/open-ports/ or
https://canyouseeme.org/
[NOTE: You will not get an OPEN state UNLESS THE MOSQUITTO BROKER IS RUNNING]
Step 7: If Port Shows Closed When coming In from Internet (ie not localhost)
Here's where I got tripped up. In my case, I have a Verizon Modem that ALSO has a firewall (because it has a router). I have my own wireless router, a tp-link Archer C1200, that I have plugged into the Fios Modem/Router. I started by putting the port forwarding in the tp-link. But that firewall comes after the Fios firewall so I needed to go to the first wall and do the port forward there.
And this is the second thing that is tricky. All of the online how-to's said I should forward port 1883 to the local IP address of my Linux Server, which in my case was 192.168.0.144. But that was not correct in my case. The Archer C1200 was actually the device that I needed to forward to -- it handled the correct distribution from there. It had an address of 192.168.0.152 assigned to it from the Verizon router. I still have both forwardings in place (ie the Fios and the tp-link) and my guess is that I need them both.
Now all pathways are open, you can follow the other Mosquitto instructions regarding logging, config files, Daemons, etc.
Hope this saves someone some time down the road!

how to read the channel uri from toastnotification event in windows phone

I am developing a windows phone application and I could send a message to another windows phone device based on that device's channel uri.
public static HttpNotificationChannel pushChannel;
App.pushChannel = new HttpNotificationChannel(channelName);
App.pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
{
//TODO:
}
I have below questions related to the above code:
How do I read the channelUri of the sender so that I can reply to the sender ? I see it is available in sender -> ChannelUri- > AbsoluteUri
And if sender wants to send more parameters can we add more toast xml tags apart from wp:Text1 and wp:Text2 or do we need to make use of wp:param only?
In scenario like Chat application should my code first store the channeluri of every device in some database and then when it wants to send a message to a particular user/device, it should read that particular user's channeluri based on his id or emailid ? Any other suggestion in this point on how to maintain users info for exchanging the messages ?
1.
You don't get the channel Uri, because they are not build for direct device to device communication. You have to transmit them by yourself.
2.
In a toast notification you only have these params available.
3.
Your application probably won't work without an extra server that manages the device/user/channel ids. Push Notifications are not made for direct device to device communication.
ChannelUris may change at any time, so your app has to send it to your server from time to time (recommended is on every start).
Also, notifications have a very limited payload, so you need to transfer the complete messages and user data on another way.

How to mimic an IP Address - Device Simulator Required

I'm new here...been digging around for some help but figured I would join and ask for some guidance.
I'm looking to create an app that can create multiple "fake" devices. They need an IP Address and I'm guessing able to respond to ping. Being able to respond to WMI would also be nice. Kinda like a simulator. I'd like to create up to 50,000 devices but even starting with 1 would help.
What is needed for such an app? TCP Client/Listener? I've never done something like this before so please be gentle :)
You may install Virtual Network Adapter's (driver is included with Windows OS), but i have never used this. Driver for Virtual Network Adapter is here: %WINDIR%\Inf\Netloop.inf
You may use Command line tool called DevCon to add devices by script, like this:
devcon -r install %WINDIR% \Inf\Netloop.inf *MSLOOP
Installation unfortunatelly takes few seconds (on my Core Duo 2.0 laptop).
If you need to configure a lot of network cards you may use command line netsh.
Examples:
netsh in ip set address "Local Area Connection" static 10.0.0.1 255.0.0.0 10.0.0.1 1
netsh in ip add address "Local Area Connection" 10.0.0.2 255.0.0.0
netsh in ip set address "Local Area Connection 2" 10.0.0.3 255.0.0.0
netsh in ip set address "Local Area Connection 3" 10.0.0.4 255.0.0.0
netsh in ip set dns "Local Area Connection" static 10.0.0.250
netsh in ip set wins "Local Area Connection" static 10.0.0.250
You may dump/export current network configuration to a file (to see how current config looks):
netsh interface dump > file.txt
More netsh examples
Edit: removed informations not useful in this case.
If I'm understanding you correctly, unfortunately this will not be easy as you need to virtualize network adapters to do the job you want. an IP address is bound to a nic (physical or logical), not something that can be specified in higher layer code. VMWare Workstation does include a plugin for Visual studio, so perhaps you can use it to generate many virtual nics and assign them ip's programatically, but otherwise you need to write virtual network card drivers (probably in a non-.net language) to do it, if you don't use an existing virtualization tech. you can stack many IP addresses on a nic, but the computer communicating with it will know they are all the same network entity. if thats fine with you, then just add all the IPs you want to the card you have.
on to the second part of your query, since you want the IPs to be able to recieve and send data, their addresses will have to be routable, so you can't just pick any old IP address. if you are fine being behind a NAT wall, you could use 10.x.y.z to address them, but on the outside of the nat they would all appear to be using the same public IP to the outside world. in order to expose 50k publicly routable IP addresses, you would first have to register and buy them.
lastly you can't use TCPClient to do Echo/Ping, since they use the ICMP protocol, but instead use the System.Net and System.Net.NetworkInformation namespace. Here is some VB code to send a ping just to give you the flavor of it:
Imports System
Imports System.Net
Imports System.Net.NetworkInformation
Public Class Pinger
<System.Diagnostics.DebuggerNonUserCode()> _
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
End Sub
Public Shared Function CanHostBePinged(ByVal IPAddr_DNS_OR_Host_Name As String) As Boolean
Dim p As New Ping
Dim po As New PingOptions
po.Ttl = 256
po.DontFragment = False
Dim stringOut As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE"
Dim streamOut As Byte() = System.Text.Encoding.ASCII.GetBytes(stringOut)
Try
Dim reply As PingReply = p.Send(IPAddr_DNS_OR_Host_Name, 30, streamOut)
If reply.Status = IPStatus.Success Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
End Class
I know this thread is very old, but I am posting my idea for anyone who might visit this question.
The previous answers already made clear that it is very difficult to achieve what the OP is trying to achieve. But I think if anybody needs such functionality for testing purposes there is a very easy way to achieve it.
We can create a simple web app in Node or .NET or whatever environment is comfortable. The web app's UI will allow us to do the following operations.
Create a device with IP
Mark an IP as Online or Offline.
If IP is online it is pingable, else not.
At the same time, the web app also exposes an API that when supplied with an IP says to us whether the IP is pingable or not. This way we mock the ping operation to an IP. Let's name this web app as PingMock.
Now in the original app, we can create a TestPingService which instead of pinging, sends an HTTP request to PingMock. This way we will be able to test our business logic without having access to actual IPs.
For testing business logic the final output of the PingService matters and not from where the output comes. This is how unit testing is conducted.
The PingMock web app is just an example. We can mock the Ping operation in whichever way we like.

Ericsson f3507g WWAN (3G Broadband) and AT commands

I have a lenovo x200t tablet with WWAN built into it.
I'm trying to connect to the internet using AT commands and a C# program which I am making so that the program can connect to the net and upload information on demand.
I don't want to use Lenovo's "Access Connections" as it is too complicated for the end user.
So far I have been able to use terminal to turn the card on and off, ring landlines and send SMS messages. However I can't seem to access the internet using it.
I could access the net through it before I removed "Access Connections" software/bloatware.
The commands I am using to try and access the net are:
Connect on COM7 to the modem
Send initialisation string "AT+CFUN=1"
Send AT*ENAP=1,1 as suggested here (http://www.thinkwiki.org/wiki/Ericsson_F3507g_Mobile_Broadband_Module)
Windows says it is "Identifying" the network and a yellow exclamation mark appears on the networking icon in the task bar, but the connection fails and drops off.
An IP is assigned to the "Local Area Connection 2" of 169.254.1.192 with a subnet of 255.255.0.0 - no gateway or DNS.
Definately no net connection...
Anyone got any ideas?
I got in contact with Vodafone in Australia and
their towers were not compatible with my modem. This has subsequently been fixed.
I needed a public IP from them (at no cost)
Problem solved..

Categories

Resources