Quantcast
Viewing all 132 articles
Browse latest View live

Reflections: mobile phones

I’d decided to make a good list of my previous owned mobile phones. I have blogged about it before. And made a list of it back in 2013, so it’s time for an update:

  1. Nokia 5110
    Image may be NSFW.
    Clik here to view.
    https://upload.wikimedia.org/wikipedia/commons/5/58/Nokia_5110.jpg
  2. Nokia 3210
    Image may be NSFW.
    Clik here to view.
    Nokia 3210.jpg
  3. Nokia 5210
    Image may be NSFW.
    Clik here to view.
    https://cf4.s3.souqcdn.com/item/2013/04/28/64/51/46/item_XL_645146_1899588.jpg
  4. Alcatel 511
    Image may be NSFW.
    Clik here to view.
  5. Motorola T720
    Image may be NSFW.
    Clik here to view.
    https://www.technopat.net/db/wp-content/uploads/2016/10/Motorola-T720-600x600.png
  6. Sony Ericsson W800
    Image may be NSFW.
    Clik here to view.
    https://i-cdn.phonearena.com/images/phones/4611-large/Sony-Ericsson-W800-0.jpg
  7. HTC S710 (first Windows Mobile phone for me)
    Image may be NSFW.
    Clik here to view.
    https://image.coolblue.nl/600x315/products/48538
  8. LG Cookie (worst phone ever!)
    Image may be NSFW.
    Clik here to view.
  9. HTC Touch Diamond 2 (2nd Windows Mobile)
    Image may be NSFW.
    Clik here to view.
  10. HTC Desire (Android 2.x never got to 4.x)
    Image may be NSFW.
    Clik here to view.
    http://jphellemons.nl/posts/files/image1.jpg
  11. HTC Desire C (Android 4.x never got to 4.1 etc.)
    Image may be NSFW.
    Clik here to view.
  12. Nokia Lumia 920 (Windows Mobile 7, 7.5 and even Phone 8)
    Image may be NSFW.
    Clik here to view.
  13. Nokia Lumia 930 (Windows Phone 8)
    Image may be NSFW.
    Clik here to view.
  14. Microsoft Lumia 950 (Windows 10 Mobile)
    Image may be NSFW.
    Clik here to view.
  15. Nokia 8 (Android 7 or 8, now running 9)
    Image may be NSFW.
    Clik here to view.
    http://cdn.eglobalcentral.nl/images/detailed/59/nokia-8-dual-sim-4gb-ram-64gb-blue.jpg

There are rumors about the Nokia 9 which seems awesome, but I've also heard good stories about the Xaomi Mix serie. I will stick to my Nokia 8 for a bit longer.

Image may be NSFW.
Clik here to view.

Enable Android Auto in a VW Golf Variant 2018

My previous blog post was about my history with mobile phones. How I have switched from Windows Mobile to Android to Windows Phone and back to Android. I have had a temporary car in the beginning of this month. It was a highline Volkswagen Polo which contained the native Volkswagen RS multimedia system. Android Auto worked perfect. Of course I had to download the .apk myself on the phone. But there are plenty of guides explaining that. I was really excited that my new car (Volkswagen Golf) Image may be NSFW.
Clik here to view.
photo
would contain a Pioneer system. It was the Pioneer AVIC-EVO1-G72-BBF which has Apple Carplay and Android Auto. I connected my phone with a cable and…. nothing. So I called the Volkswagen dealer and they had to look into it. I got a call back that I would not have that option which seemed weird to me because it was the top most feature on the Pioneer website. After a few days my wife connected her iPhone to charge it and it launched Apple Carplay. I was blown away and took a look at the manuals that I found in the dashboard glovebox. In the installation manual it mentioned on page 8 that you had to connect a USB to a specific port on the back of the Pioneer. So that would explain that Carplay works and Android Auto did not. So I mailed and called the dealer again and they told me to bring the car in.

Image may be NSFW.
Clik here to view.
integration-manual

It took them over three hours to switch the cable on the back and test it. They could not get it to work. They even called Pioneer support and got an answer that it was not supported and would not work. They retrieved a brand new Pioneer system from the warehouse and it was largely displayed on the outside of the box that it would have Android Auto support. So a lot of effort and still no Android Auto. But at least the radio was connected to USB 2. I searched a while online and found this link. I thought it would not affect me because I do not have a Pixel. But I do have USB-C (Nokia 8) and when they delivered the car, there was an USB extension cable in the glovebox so I decided to give it a try. And it finally worked. So buying a short USB-C did not help me, because due to an issue on Pioneers end, I will always need an extension cable Image may be NSFW.
Clik here to view.
Confused smile

Next step: try to update firmware of the adapter and the system itself. Currently I just keep getting incompatible USB stick. Even when it’s formatted as FAT32 filesystem and only has the firmware file on it in the root directory.


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Image may be NSFW.
Clik here to view.


Image may be NSFW.
Clik here to view.

Image may be NSFW.
Clik here to view.

Docker for Raspbian Buster 10 on a Raspberry Pi 3 and RabbitMQ

Recently the Raspberry Pi 4 was announced, But I am currently using my rpi 3Image may be NSFW.
Clik here to view.
test_1
and want to run Rabbit MQ on it in Docker. So I used these two commands to get it to work and I just wanted to share it:


sudo rm /etc/apt/sources.list.d/docker.list;

curl –sL get.docker.com | sed ‘s/9)/10)’ | sh

If you would like to use Docker as a non-root user you should add your user to the docker group:

sudo usermod –aG docker pi

To get Rabbit MQ (which has arm container) on the pi with a management web interface run:

sudo docker run –d –hostname my-rabbit –name some-rabbit –p 15672:15672 –p 5672:5672 rabbitmq:3-management

Then get the ip of the docker container with (but since you added the ports in the previous command, this step can be skipped):

sudo docker inspect –f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ some-rabbit

Then you can launch a browser and go to http://thatipaddress:15672 and login with 'guest/guest'. If you did not lookup the ip of the container you can use the ip of the pi because you opened container ports when running it.


Image may be NSFW.
Clik here to view.
8850828555_df7c7bd300_b


Good luck!

Image may be NSFW.
Clik here to view.

Code coverage .Net core unit testing

As you have noticed, you need Visual Studio Enterprise for live unit testing, or Jetbrains Rider, or some Visual Studio Code “hacks”. Here is a method to have coverage of .Net core with a global tool:

Image may be NSFW.
Clik here to view.

Daniel Palme has a global tool version of Report Generator. You should install it once with:

dotnet tool install -g dotnet-reportgenerator-globaltool

dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools

You can then run it with `reportgenerator` so after building I run:

dotnet test --filter FullyQualifiedName~UnitTests /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*Test*]" /p:ExcludeByAttribute="GeneratedCodeAttribute"
reportgenerator "-reports:**\coverage.opencover.xml" "-targetdir:C:\Temp\Reports\" "-reporttypes:HTML"
Start-Process -FilePath "C:\Temp\Reports\index.htm"

Of course you can go to the project properties and add the three lines of powershell to a file in the root of your solution and add to the build events tab as post-build:

Powershell -File "$(SolutionDir)nameOfPowershellscript.ps1"

Good luck!

Image may be NSFW.
Clik here to view.

SonarCube in Docker and .Net Core

When you have a nice .Net core solution and want to see the code smell and technical debt, you can analyze it with SonarCube

Image may be NSFW.
Clik here to view.
SonarQube

I started by browsing to the docker hub and used a container:

docker pull sonarqube

docker run -d --name sonarqube -p 9000:9000 sonarqube

The default username is ‘admin’ and the default password is ‘admin’ so once it is started you can head over to http://localhost:9000 and login. Configure your project there and copy the key/hash

You can get the SonarLint extension for Visual Studio and Visual Studio Code and link it to the local SonarCube server.

You need this one time installation of a global tool:

dotnet tool install --global dotnet-sonarscanner --version 4.3.1

And then:

dotnet sonarscanner begin /k:"project-key" 
dotnet build <path to solution.sln>
dotnet sonarscanner end 

Wait a minute after it finishes so that the SonarCube server has some time to process the results. Check the dashboard again to see the smell, bugs and tech debt. This does help you verify if you are still coding SOLID.


Happy coding!

Image may be NSFW.
Clik here to view.

Pi hole, no more ads in your LAN

There are a lot of guides on how to install Pi-hole on a pi. I just used the win32DiskImager to put Rasbian on it and I did put an ssh.txt file on the SD card to enable SSH. I just had to plug it in the pi and wait for it to show up on the DHCP list of my router so that I knew the IP to ssh to.

I have an archer c7 router which has “DNS rebind protection” so I could not change the DNS to the local IP address.

In order to fix it I had to go to the Archer web interface and follow these steps:

Add in dhcp –> dhcp settings, set the primary DNS to the local ip

in the dhcp –> address reservation “add new “ paste the mac address which you can find in dhcp –> dhcp clients list.

and the local ip which the pi has. This makes sure that the next reboot, the pi/dns server will have the same lan IP.


By the way, I had an issue with the ‘ftl’ part in the installation of pi-hole

I fixed it with : `sudo nano /etc/resolv.conf`

add a line with: `nameserver 8.8.8.8`

That is the google dns and that makes sure that there is a know dns so that the installation can lookup ip’s and continue.

Save the .conf file and run `sudo bash /etc/.pihole/pihole –r`


That will repair the installation and the FTL part will succeed now that there is an dns entry to the google dns in the resolv.conf


Good luck!

ps. please let me know if you know a way to block youtube ads. No browser plugin, but a pi-hole solution please.

Image may be NSFW.
Clik here to view.

Why I did not make a Teddy Bear hunt app

To keep kids entertained, people from all over the world put a teddy bear in their window so that kids can spot them during a walk.

I don’t know the origin. It’s in Canada, USA, New Zealand, UK etc. It’s also in my hometown so I decided to make an app for it.

People made a Facebook group with a google form to submit the teddy bear and an URL with all bears on google maps.

I thought that I had to get access to the Google spreadsheet containing the data, but it seems that it would not hold that much info if we take a look at the entry form and the maps data. In Google maps you can download a KMZ file which is a zipped KML (Keyhole Markup Language) It’s XML. Here is the full KML:

Image may be NSFW.
Clik here to view.
full-kml

So there is a web link in it to get the live data. I used the webclient to pull it in and read it and tried to make pins out of it.

My first step was to add the Xamarin.Forms.Map Nuget package and the SharpKml.Core

Here is the full code:


private void AddMap()
{
	var map = new Map(MapSpan.FromCenterAndRadius(new Position(51.697815, 5.303675), Distance.FromMeters(10000)));

	using (var client = new WebClient())
	{
		var kmz = KmzFile.Open(client.OpenRead("https://www.google.com/maps/d/u/0/kml?mid=1kedGv2twtsWmzgxRpZcu5hr-qpE77plL"));
		Kml kml = kmz.GetDefaultKmlFile().Root as Kml;

		if (kml != null)
		{
			foreach (Placemark placemark in kml.Flatten().OfType())
			{
				Console.WriteLine(placemark.Name);

				var pin = new Pin()
				{
					Address = placemark.Address,
					Label = placemark.Name,
					Type = PinType.Place
				};
				map.Pins.Add(pin);
			}
		}
	}

	this.Content = map;
}

But the pins won’t show up (of course). Because I did not set the position. The real Kml contains data like this:

Image may be NSFW.
Clik here to view.
kml-detail

So as you can see there is no Latitude Longitude for the placemarks… So how does google maps work then? It seems that both Google Maps and Google Earth Geocode the address to get the lat lng. But that service unfortunately is not free. I tried to load the kml in Google Earth and export it, but that also does not add the latitude and longitude. I also thought that kml support for the map control could be used. So that I could just provide the kml to the map and have it sort it out, but that was build with monoandroid 9 instead of netstandard2.0 and would probably not fix the geocode issue.

I planned to make an app with no central backend. But because of geocoding, I would have to use a webapi or Azure Function to keep track of the “database” with all teddy bears and their corresponding lat lng. That would also lower the requests for geocoding if it would be moved from the phone (client) to the server.

But I’ve not found a good free geocoder

nominatim.openstreetmap.org does not work if I would provide the kml data. I think that I will come back to this one….


Good luck making your own KML/KMZ reading app!

Image may be NSFW.
Clik here to view.

Teddy bear hunt app

In my previous post I thought that I would not make the app because I did not had a nice geocoding service. I did find Azure Maps, but there is no nice C# client at that time and I did not feel like doing manual REST calls. I know I can, I just didn’t feel like making it (sorry).

So I’ve worked in the past with the Geocoding.Net Nuget packages and decided to go for the Bing version. Googles version requires an account with billing because the first 200 dollar is free. It does feel like a hurdle for me as I do not work that much with Google Services.

So I did create an Azure Function which reads the kmz and extracts it to kml and for each unknown placemark would do a geo-location and store it in a file, so that only new bears would require a call to the Geocoding service of Bing.

The app is up now in the play store. Not in Apples App store, because I did not buy a license for it.

https://play.google.com/store/apps/details?id=com.companyname.bosscheberenbingo

I forgot to rename the package.

Here is a small snippet for the Geocoding:

var geocoder = new Geocoding.Microsoft.BingMapsGeocoder(“key”);

var geoCodeResponse = await geocoder.GeocodeAsync(“address here”);

var location = geoCodeResponse.First().Coordinates;


Good luck and happy bear hunting!

Image may be NSFW.
Clik here to view.

Use FontAwesome in Xamarin Forms

I followed this guide: https://medium.com/@tsjdevapps/use-fontawesome-in-a-xamarin-forms-app-2edf25311db4

Where you manually have to edit a XML file to get it to work in iOS and add the font for each platform you want to support. So for FontAwesome (regular, bold, brands) and UWP, Android, iOS. That gives 9 files!

which eventually works:

<Label Text="&#xf0f3;" FontFamily="{StaticResource FontAwesomeRegular}" FontSize="Large" TextColor="Red" />
         <Label Text="&#xf26e;" FontFamily="{StaticResource FontAwesomeSolid}" FontSize="Large" TextColor="Red" />
         <Label Text="&#xf26e;" FontFamily="{StaticResource FontAwesomeBrands}" FontSize="Large" TextColor="Red" />


BUT: If you would just update to Xamarin Forms 4.5.0.530 or higher

you can add a line for a font. (so 3 times something like this for FontAwesome)

[assembly: ExportFont("FontAwesome5Regular400.otf", Alias = "FontAwesome")]

to your app.xaml.cs

and use

<Label Text="&#xf0f3;" FontFamily="FontAwesome" FontSize="Large" TextColor="Green" />

in your mainpage.xaml


good luck!

Image may be NSFW.
Clik here to view.

Building a mobile declaration app

There was an email earlier this year about a change in declarations from my employer. You can’t just drop receipt on someone’s desk anymore, but since we are in a digital era, we should make a picture of it and send it by mail. That sounds fair. But that would require me to remember the constraints, like letting know for which client it is and to which address I should send it to. So I decided that it needed automation.

Because some coworkers have iPhones and some have Android, I decided to go for this approach:

Image may be NSFW.
Clik here to view.
architecture

Xamarin Forms (Android, iOs) post a picture of a receipt to Azure Functions in the Azure cloud which sends it to Sendgrid. (Because Azure Functions cannot send mail)

Here are the steps I took to make a simple camera app:

1. File, new project, new Xamarin Forms project (no web api)

2. Add new project to solution (Azure Functions)

3. Add the nuget package ‘Xam.Plugin.Media’ to the shared/main xamarin project

4. Add UI code:

5. Add code to cs (code behind file)

I had three class variables (type string) filePath, filename, url (url to your azure function) I forgot that the emulator is a vm so you can’t use the localhost if you are testing the Azure Function but you should use your LAN ip.


private async void takePhoto_Clicked(object sender, EventArgs e)
{
	if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
	{
		await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
		return;
	}
	filename = DateTime.Now.ToString("yyyyMMdd-") + Guid.NewGuid() + ".jpg";

	var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
	{
		PhotoSize = PhotoSize.Medium,
		Directory = "Sample",
		Name = filename
	});

	if (file == null)
		return;

	filePath = file.Path;

	image.Source = ImageSource.FromStream(() =>
	{
		var stream = file.GetStream();
		file.Dispose();
		return stream;
	});
	sendPhoto.IsEnabled = true;
}

private async void sendPhoto_Clicked(object sender, EventArgs e)
{
	HttpContent fileStreamContent = new StreamContent(File.OpenRead(filePath));
	fileStreamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") { Name = "file", FileName = filename };
	fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

	using (var client = new HttpClient())
	using (var formData = new MultipartFormDataContent())
	{
		formData.Add(fileStreamContent);
		var response = await client.PostAsync(url, formData);
	}
}

6. add `await CrossMedia.Current.Initialize();` in the android project in the mainactivity.cs just below the OnCreate call

7. add this code to the azure function:


string imageBase64;

using (var ms = new MemoryStream())
{
	file.CopyTo(ms);
	var fileBytes = ms.ToArray();
	imageBase64 = Convert.ToBase64String(fileBytes);
}

string sendgridApiKey = "api-key-here";

var client = new SendGridClient(sendgridApiKey);
var from = new EmailAddress("mymailaddress@partech.nl", "JP Hellemons");
var subject = "Declaraton from app";
var to = new EmailAddress("mymailaddress@partech.nl", "JP");

var msg = MailHelper.CreateSingleEmail(from, to, subject, "plain msg", "html version");
msg.AddAttachment(file.FileName, imageBase64, "image/jpeg", "attachment");
var response = await client.SendEmailAsync(msg);

return new OkObjectResult("");


8. of course make a free account at sendgrid and just follow the tutorial/docs for adding the nuget package to the Azure Function.


Next post will contain a link to the Azure Active Directory for authenticating so that not everybody will send in receipts on my behalf.

Good luck!

Image may be NSFW.
Clik here to view.

Add Azure Active Directory to Xamarin Forms app

As I’ve previously blogged, I created a Xamarin Forms application to submit pictures of my receipts to the company I work for. But if I’d publish the app in that state, the whole world could send in receipts on my behalf. So I needed to add authentication. Because the company uses Office 365, I’d decided to add Azure Active Directory.

There are a lot of resources about Adal (Active Directory Authentication Library) Some call it Azure Adal.NET

You can read about it on the Github page

https://github.com/AzureAD/azure-activedirectory-library-for-dotnet

It is also very clear in the readme.md that you should in fact upgrade to MSAL.Net

MSAL.NET is the new authentication library to be used with the Microsoft identity platform”

Searching for Xamarin.Forms and Msal.Net did not gave me that much options, so I decided to blog about it.

MSAL stands for MicroSoft Authentication Library. The Github is https://github.com/AzureAD/microsoft-authentication-library-for-dotnet

It’s for Oauth2 and OpenID connect.

I started with adding an application registration in the azure portal under azure active directory at “app registrations”

I switched to “Single tenant” at the authentication tab/page to make sure that only people from within Partech are allowed.

Further more you need to write down the app (client) id and the directory (tenant) id.

Next was the code integration:

1. add nuget ‘Microsoft.Identity.Client’ to the Xamarin shared app

2. make sure your app.xaml.cs looks like this:


public static IPublicClientApplication PCA;
private const string applicationClientId = "clientidhere";
public static string[] Scopes = { "User.Read" };
public static string Username = string.Empty;

public static object ParentWindow { get; set; }


public App()
{
	PCA = PublicClientApplicationBuilder.Create(applicationClientId)
		.WithTenantId("tenantid here")
		.WithRedirectUri($"msal{applicationClientId}://auth")
		.WithIosKeychainSecurityGroup("com.microsoft.adalcache")
		.Build();


	InitializeComponent();

	MainPage = new MainPage();
}

3. to the mainpage I added an override of OnAppearing which called an async CheckAuth

4. add this code to checkauth:


AuthenticationResult authResult = null;
IEnumerable accounts = await App.PCA.GetAccountsAsync();
try
{
	IAccount firstAccount = accounts.FirstOrDefault();
	authResult = await App.PCA.AcquireTokenSilent(App.Scopes, firstAccount)
						  .ExecuteAsync();
}
catch (MsalUiRequiredException ex)
{
	try
	{
		authResult = await App.PCA.AcquireTokenInteractive(App.Scopes)
								  .WithParentActivityOrWindow(App.ParentWindow)
								  .ExecuteAsync();
	}
	catch (Exception ex2)
	{
		DisplayAlert("Acquire token interactive failed. See exception message for details: ", ex2.Message, "Dismiss").RunSynchronously();
	}
}

if (authResult != null)
{
	await GetHttpContentWithTokenAsync(authResult.AccessToken);
}

5. for the rest of the code to retrieve the users given name, surname etc. you should check the GitHub link I mentioned previously.

To do more with azure AD use the Graph explorer

Good luck coding!

Image may be NSFW.
Clik here to view.

Stake Neblio on your pi

Viewing all 132 articles
Browse latest View live