Sunday, December 13, 2020

Communicating with Apple Web Services (GSX) via Filemaker 3

 My previous blog talks about communicating with GSX using JSON. There is one area which is not mentioned. This area concerns with security. GSX requires client certificate issued by them and a white-listed IP. They require user to be certified and communicating from an approved IP address.

The white-listing is easy to achieve. Just designate your server/computer as the channel to communicate with GSX. All API requests have to be send from the server/computer. This means that if you require multiple user access, then you must provide a means for all of them to communicate with GSX from the white-listed server/computer from Filemaker using the "Insert from URL" function.

Getting a cert from GSX is done by sending a properly filled CSR to GSX. Note that the Common Name is defined by GSX. It is used to identify user according to GSX format. With the cert, you need to prepare it for use by the server/computer so that you can use it. The following is example done in PHP. The method used is via CURL in PHP.  It is not advisable to use Filemaker to communicate directly with GSX as each "execute from server" means one connection used. You may soon find out you run out of connection on your server. By using "Insert from URL" and calls a PHP server, there is no limit.

Before you could start coding the PHP, you need to prepare your cert for use in CURL. CURL works best with certs in the PEM format. You need to combine the cert and private key into one file by copying and pasting the cert and key into a single pem file.

The following is a typical CURL setting

$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_VERBOSE, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

curl_setopt($ch, CURLOPT_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_HEASDER_OUT, true);

curl_setopt($ch, CURLOPT_SSSLCERTTYPE, 'pem');

curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'pem');

curl_setopt($ch, CURLOPT_SSLCERT, 'your cert');

curl_setopt($ch, CURLOPT_SSLKEY, 'your key');

curl_setopt($ch, CURLOPT_SSLKEYPASSWD, 'your pass');

You will have to check the documents to see what are the headers required to be sent to GSX. I suggest you send the header settings from your user to the server/computer as JSON then convert the JSON as array with variable name as $headers as shown above. In addition, not all GSX API calls are POST. You need to get user to indicate whether the request is POST or GET.

If it is post then you will need to set the following

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $content);

curl_setopt($ch, CURLOPT_URL, 'your url');

Since a GET requires CURL GET request, you need to define it with the following.

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

Each API requires the API to be defined as part of the URL. You need to define the URL for each API call. Compose the URL from the user side and send it as a parameter to the server.

curl_setopt($ch, CURLOPT_URL, 'your url');

Finally execute the CURL

$output = curl_exec($ch);

It is a good practice to always close the CURL after every thing is done.

Now CURL may return two different errors. One from CURL itself, the other is from GSX. Your error message have to distinguish between the two.

Before you even start to test the PHP coding, you need to obtain an initial ID from GSX. Therefore, you have to visit https://gsx2.apple.com/gsx/login to sign in and get the ID. This id will be used to obtain the proper ID for subsequent GSX API request by calling the "authenticate token" api then copy the ID returned for subsequent use.

A final oddities is that if you, or your users, use more than one app or one computer that access GSX. Please be reminded that only one ID is provided at anytime. You need to use the same ID for all requests. It is up to you and your user to store such ID in one secure place and use it to consume APIs.







Monday, December 07, 2020

Internet Download Speed is Crawling

 Quite some time ago my win10 browser loading suddenly become sluggish. I check with Ookla Speed Test shows that the download speed is just 6 mbps whereas I subscribed to 1 Gbps. The upload speed is very much faster but still well below the 1 G bit as subscribed.

Tried various methods of finding out why the download is slow but to no avail. Checking the speed on my handphone proved that the router is OK thus not service provider problem. It is only the laptop that has the problem. It really puzzles me as it is not due to browser issue since Ookla has a app that could perform the test without using browser.

After a month or so of intermittent attempts to find the fault, I finally found a clue. Netizens mentioned that SmartByte Network Services could slow down network.

I uninstalled SmartByte and the speed went up to almost 1 Gbps. SmartByte come pre-installed with Dell laptops. There are instructions in the internet that teaches you how to uninstall it. One such example is https://windowsreport.com/smartbyte-services/.




Monday, November 09, 2020

Getting the distance from a QR code with known dimension

 In working towards an app that guide VI to navigate indoors (Blind Navigation System Using QR Code), I am working out the distance of a QR code from the navigator. This will allow the app to works like iBeacon that could tell the distance of navigator from the device.

OpenCV already have methods that could measure object dimension from a known reference. The first step is to convert the known dimension to pixel ratio. This will allow for different camera with different megapixel count. The formula is simple. ratio=pixle/real size of object.

With this constant, I will need to determine the distance from the navigator to the QR code. First I find the QR code then measure the QR Code size. The QR code most likely have to be enclosed within a rectangle so as to allow the measurement of the rectangle. Convert this size (in pixles) by the formula size=pixle*ratio. Viola, we get the distance from the QR code.

Measuring the position of the QR code is an essential metric. This will allow navigator to know the direction towards the QR code. This is easily done by getting the center point of the camera view then get the relative position of the QR code to the center point. We can inform the user whether it is to the right or left. Calculating the distance from the center point is quite meaningless as it is not useful to the navigator.

Unless navigator has a perfect memory of the position of all the QR code, there is a need for a map of the location with precise point of all the QR codes. The app should also allow the plotting of routes from one QR code to another so as to provide a voice guided navigation for the VI.

Deviating from the QR code will be an issue. Unlike iBeacon, once the QR code is not in the camera view, VI is practically lost. A facility to turn VI back to the track has to be made by approximating the last known point.




Tuesday, October 27, 2020

digiKam Used for Managing Flora and Fauna Photos

 I need to use an application that could manage those photos of flora and fauna so that I could easily refer to them or search for specific specie. After the demise of Picasa, I found an application called digiKam that could perform most of the functionalities like Picasa. 

digiKam has lots of functionalities that are available. Here I will only talk about those I would use to manage flora and fauna photos.

Showing photos that are stored in directories grouped by directories is the basic requirement. It won't work if I have to go to individual directory to show the photos inside. digiKam did a good job by showing an entire directory with subdirectory as a selectable list.

In addition to directory aka Album, digiKam is able to show lists by Maps, Tags and Dates. It also have a search by title. Other list types are available but is of little use to me. Tags list is mentioned together with Tag editing below.

Maps listing is an interesting feature. You can show a list of photos that is defined by a square selection or select a group of photos that is grouped by digiKam. I find it extra useful to identify flora pictures. It all goes by memory. If you have seen the flora before and remembers a rough location, you could list the photos in the area and try to find the flora. For fauna, it is a bit difficult as they don't stay in the same place unless they are territorial.

I also contributes to iNaturalist. The location can match with digiKam map to show a list of photos in the same area. It helps if I have already identify the flora and have a picture of it. Inversely, I could use my photo's location and find in iNaturalist to see if there are any observation of the same kind. iNaturalist have the same map area list like digiKam.

GPS, Tags and Title are the most important information that is stored in a picture. digiKam allows the editing of these tags as individuals and group editing. 

Tags are usually done as a list. digiKam stored hierarchical tags in its database. It did not store the data in the pictures because other applications only look at tags as a list. This feature is best suited for me as I normally set the taxon family and Gender as separate tags. digiKam is able to use tags to show the list of photos that has the same tag. Now I could use the hierarchical listing to see the gender in a family instead of seeing the whole list of photos in the same family. 

Tag editing also benefits from the hierarchical arrangement. When adding tags I had to find the family and gender separately before adding them. Now I just need to find the gender and the family will also show up if it already exists. This save me from having to find the family name for the gender.  A time saving feature.

Zooming is a very useful tool. digiKam allow list photo to be zoomed to a size comfortable. I zoomed to a level that shows 5 photos in a row. That is most comfortable to see enough details of the photo. 

By double clicking a photo you could see a zoomable view of the photo. It even have a full screen zoomable view of the photo. You could set it to full screen when you double click. This is very useful to see clear details of the photo so that I could find the specific character of the flora and fauna.

Rotation. Sometimes the camera does not automatically store the rotation thus digiKam showed the photo in the wrong position. digiKam has a rotation setting so that you could view it properly. However, I am not sure if the information is stored in the picture after that. 

Photo editing. Not the usual kind of editing feature is available. It is just a set of enhancement that allows photos to be adjusted. I usually use auto color to adjust the photo. Other adjustment features may be useful but is of less interest to me.

Grouping in a list. It is a unique feature but it does help if you go for a tour and need to group the photos by the day. You could group the photos in anyway. I find it useful to avoid seeing those photos that are not related to flora and fauna.

Panorama is not part of the feature required for flora fauna management. But it is useful for people who does not have a panorama camera to stitch few photos together to make a panorama view/ However panorama is not a digiKam application. It has to be installed from outside. Luckily when you select panorama in digiKam, it allows you to download hugin (pto2mk) and GnuWin (make) from internet. Download and install, the panorama feature will be activated.

In conclusion, it is useful to me to manage my photos in the flora and fauna sense. This application is available for Windows, Mac and Linux.






Wednesday, October 21, 2020

Do I Have a Problem with NParks

 I have been posting messages and articles about NPark's not doing a proper job. It all started some years ago. I reported a tree fallen over the McRitchie route. No replies whatsoever.

In Jan 20 2013, I went cycling with a Facebook cycling group, saw quite a number of cyclist fell at Mandai PCN. The path was covered with slippery moss.

In March 2013, I posted in Facebook cycling group that PCN is not cycling friendly.  See https://jnhiew.blogspot.com/2013/03/is-pcn-really-for-cyclists.html. The host suggest me to give a list of actual places that needs improvement. I went from Woodlands to Yishun then showed a list of the issues faced. There are 32 photos I took. Some are rectified over time. Below is just some of it. It showed almost 90 degree turns and exit into pedestrian path with obscured view.





Jan 22 2014 saw a tag that is not appropriate. How does the MP plant a family of plant as a tree?


April 12 2014 mentioned about badly designed PCN.



July 10 2014. Mentioned Daily Farm PCN become a jungle.


August 21 2014 saw a tag that is badly misspelled.


August 20 2014. Flooding again.


Jan 18 2015. Algae problem on PCN.


July 25 2015. Careless work.



April 3 2016 noticed an error on the position of Chestnut Nature Park. Posted it on Facebook. It has been corrected.


Nov 27 2017, flooded PCN.


April 30 2017 tried the new PCN. Not a good experience.


May 1 2017, jumping the gun. Misleading. Make people think that it is completged.


July 25 2017 Unchecked work again.


On 30 March 2019 the coast to coast 36KM route was launched. I mentioned on FB cyclist group that it is not cyclist friendly thus is for walking only. See https://www.facebook.com/groups/lovecyclingsg/permalink/2209026995821303. It  provoked a few people. However, I coolly explained that it is the media that says its for cycling and that I do not obliquely say NParks did a poor job. But actually 36KM is not for average people. It starts from Coney island which is quite a distance from bus stop. Since it is not cyclist friendly, it is not suitable for cycling also. So it is neither here nor there. I would question why they design a hiking only route instead of catering to both pedestrians and cyclist too.




Jan 10 2020, New Flora and Fauna web is a let down. It has since then been redesigned.



 Oct 18 2020 another web fumble.


Oct 21 2020, yet another fumble in information technology.



Oct 21 2020 You would expect NParks update its web page on PCN tracks. Its not. The new Changi Airport PCN is yet to appear after one and half week of its debut. I guess they are more interested in Jurassic Miles instead.


Nov 11 2020 posted on Facebook group and Tweeter about PCN being blocked and a sign to "dismount and push" because accidents happened there.


Nov 12 All the species of trees have gone missing.




Dec 8 2020 commented on TODAY group about Jurassic Mile being a PCN yet is too narrow with many pedestrians around and the hated "dismount and push" signs.



After all the above posts, people may just wonder whether I am indeed finding faults with NPark. My motto on Windows into Life is "Veni Visi Scripsi" (I came I saw I wrote). It spells exactly the attitude when I am writing the posts. NParks is not the only one I mentioned. It just happen that I come across problems while looking for something else that is of interest to me. NParks happened to be related in the things I looked at.


Tuesday, October 06, 2020

Media Article and Response of Reader

 

Recently the Straits Times published an article "Silvia Lim's Motion on Parti Liyani case not picked for Parliament Sitting". There were quite a few exchange of words between MPs and readers.

The article's choice of words are entirely the author's in the author's own understanding and expression. It may be carefully crafted to make the title striking or perhaps crafted to mislead people. However, in the context it was clearly stated that it was "decided by ballot".

The question on whether it is deliberately crafted to mislead or just simply stroking reader's reaction is best left to the author since it is worded by the author. The author may well be in the "you know" mindset that assumed reader understand the title by reading the context. Thus, the choice of word is entirely the author's "bias".

On the readers' side, it may be entirely misunderstanding of the title coupled with the lack of interest in the context or lack of knowledge in Parliament Process  or deliberately reading the title out of context before commenting. Other readers reading the content is thus lead in the comment to belief what was stated and thus MP responded by lashing out. This is typical readers mindset. They formulate the message entirely in their own understanding of the title. Again is is said to be readers' "bias".

Obviously, there will be others who jump in the wagon and make a scene out of it like the article published in "The Independent" showcasing MPs and readers comment thus making a case out of it.

There is no way in stopping the authors' choice of word in the title and no way to stopping readers to response in anyway they like. One must be aware of the subtle messages conveyed by the title yet understand that it could be just plain inadequate portraying an incident or a deliberate means of attracting readers' attention misfired. The author's article would have been vetted by the publisher before being published. Depending on the bias of the publisher, it is then shown to the public as an edited article. 

Since (according to some) the publisher is pro-government, it may well be a gimmick backfired rather than "bias" as stated by Tan CJ in his comment.




Saturday, October 03, 2020

Blind Navigation System using QR Code

 My previous blog talks about using RFID for navigation. The only problem is that the reader is not cheap and is hard to come by. This blog talks about an alternative for the RFID.

QR code is good because it can tolerate high margin of errors.  QR code can be scanned using a hand phone. Thus the data and the reader is available cheaply. QR Code need not be read from a close proximity. Just enlarge it and it can be read from a distance. 

I tried a two inch square QR code (1234-56) and it can be read from a meter away. Proportionally, a 5 inch (12.7 CM) should ideally be read from 5 meters away. In actual fact, it can be read at 3 meters distance only . However, that will be good enough otherwise it cannot fit the camera view at close distance.

The use of it is similar to RFID. There is a mapping of all the QR code within the area. They are placed 3 meters apart. 3 meter is used to ensure that the next QR code is within scanning distance. Using the same triangulation method of the RFID, the same navigation method can be done.

Obviously, the QR code should be hanging high enough so that human traffic will not obscure it. Since it is passive, Visual Handicapped may totally lost trace of it and wonders off course. Illumination is also a issue unless the place is perpetually lit.

See my post on RFID here.




Friday, October 02, 2020

玄幻小说

 近来无聊的去看网上玄幻小说。看了几篇后有感想。他们大都采用同种格式。都有抄袭的嫌疑。不但是抄袭而且一直重复。以下是一些范例。

1. 穿越 - 死后穿越到另一个世界。附体于另一个人的身体。美名为夺舍。

2. 进阶 - 故事通常为武术。可以进阶。 进阶时是以梯级式而不是线性累进的。跟网上游戏一样。

3. 夺宝 - 时常有秘境开放。有进阶上限。进去时会分开。时间到会自动弹出。宝物常有武功传承,武器,药物,进阶等。

4. 异兽 - 像人一样有阶段。生体内有灵晶。

5. 竞选 - 不同形式的武术比赛。

6. 地位 - 进了宗门有外门,内门,精英等分别。要往上爬就必须进阶或比赛。

7. 闯关 - 通常有几层的。失败的会被弹出或死亡。

8. 成神 - 不少小说主人会成神或仙。会升仙。

9. 同阶无敌 - 通常是越阶挑战。

10. 灵药 - 灵药生长地一定有灵兽保护。

11. 天谴 - 进阶到某种程度,修炼超世而受天惩罚降下九道雷劈。

12. 不死 - 人被打死死了灵魂可以离体找人夺舍重生。

13. 储物戒指 - 可大量的储存物资。

14. 离题 - 作者会加上个人写作感想或请求。

15. 法则 - 武功的一种。时间与空间法则为最厉害。

16. 领域 - 另一种武功。

17. 大话 - 在打斗前对方常说的话。

18. 自废 - 对方常没开打就叫主角自废后给他全尸或自己断手脚。

如果情节完美结束那还可以接受。某些作者半途以主角死亡结束或没头没尾的完章。有一个作者完全迷失情节搞到主角变成另一个人然后突然结束。









Sunday, March 22, 2020

Telling lies

From the bible the biggest lie that was told is in Genesis 3:4 "You will not certainly die". Gen 2:17 clearly says "for when you eat from it you will certainly die".

Now what is a "lie"?  According to Cambridge English Dictionary, "something you said that you know is not true." In Gen 3:4, the serpent knows it and tried to deceive Eve, the woman that is created after Adam was told not to eat the fruit. The reason why the serpent lie to Eve is that she does not receive the command from God thus only knows the command second hand. This is not to say that woman is weaker than man just that the doubt is planted by the serpent on a person who does not receive the command directly. That person happened to be Eve. If it is Adam that defies God, directly mankind probably no longer exists.

The wider purpose of a lie is to gain something from a lie for personal benefit. The serpent lied so that it could destroy faith in God. For most people, it is just to benefit self.

When a person tells a lie that could prevent the lost of a life other than your own, is that still a lie? Literally it is still a lie but it is used for a different purpose. During WW2, Chiune Sugihara issued visas to Jews despite being told not to. He lied so that 6000 Jews could live. What does he gain? A dismissal from foreign office. He and his family felt no shame on it because it served a higher purpose.

We are just little people but often we have to tell lies just to avoid embarrassing the person we lied to. We gained little from telling the lie. It is wrong to tell lies to prevent embarrassing ourselves or cover our wrong doing.

Real lie is from people that tried to achieve gains from it. The lying person tell lies that could benefit from it or served his/her purpose. They tell lies to gain from others or prevent damage to themselves.

Lying is not just for monetary gains. It could be used to destroy faith in the person or state. For example, giving false statements. Singapore has a law against POFMA (Protection from Online Falsehood and Manipulation Act). Although it could be used to deter people from telling the truth, it generally prevents ill hearted people or group that tries to destroy others.