Door 1 - Barcodes
|Fact of the day
|Did you know that you can generate over 80 different barcode types with MBS?
Welcome to the first door of our advent calendar. In this advent calendar I will introduce you to various components of the MBS FileMaker Plugin and show you how to use them. Today it's all about barcodes. Did you know that you can create over 80 different barcode types with the MBS FileMaker Plugin? How this works I will show you today in a project in which we create a WIFI QR code. If your guests get bored over the Christmas period, they can simply scan this QR code with their smartphone to gain access to your WiFi.
First of all, let's consider the question of how such a WiFi QR code is actually structured. The information you need for the QR code is the SSID, In other words the network name, the access password, the type of WiFi encryption and the visibility. For this test, let's imagine we have a WLAN with the following data:
Encryption WPA 2
First of all, we have to specify in the QR code that it is a WIFI QR code, so we first enter the service tag WIFI. This way, many QR code scanners know what to do with the information. Now the information about our network follows. The individual information is provided with an associated key so that you know what information it is. The key and the corresponding value are separated from each other with a colon. The individual values are separated from each other with a semicolon. The QR code type is followed by the used encryption protocol. The key to the encryption protocol is T, followed by the information on the protocol. For the protocols, we have the choice between WPA, WEP and nopass. We use WPA in our example. This is followed by the key S for the SSID and the corresponding value. If the WLAN requires a password, this is specified with the P key. If there is no password, the value remains empty. Now we need to specify the visibility of the network. Here we can only choose between the values true and false. If it is hidden then our value is true, if it is visible then the value is false. The corresponding key is H. If the network is visible, we can also omit the value here.
For our example network, this would be the content of the QR code:
In our example, we have a field for each of the entries and a container in which the image of the barcode should be displayed.
Now we come to our script with which we create the Wifi code. We have two options for this. We can use the Barcode.Generate function and pass it the constructed string. We can also define further properties for the QR code in the other parameters, but more on that in a moment.
Or we can use the Barcode.GenerateJSON function. We pass it a JSON with our settings. In this example, we choose the Barcode.Generate function.
First, we assemble the string.
Set Variable [ $Text ; Value: "WIFI:T:" & DoorOne::Encryption & "; S:" & DoorOne::SSID & ";P:" & DoorOne::Password & ";H: "& DoorOne::Hidden &";" ]
We want to create a QR Code with a high ECC level. We can select an ECC of 1-4. A high ECC level helps us to recognize a barcode better, even if parts of the code are missing, because the information in a QR code appears several times. The higher the ECC level, the more extensive the QR code is, but the higher the chances of it being recognized. For a QR code, we need to assign the value 4 to option1.
Set Variable [ $r ; Value: MBS( "Barcode.SetOption"; 1; 4) ]
Now we call the Barcode.Generate function. In the first parameter we specify what type of barcode it is, in our case a QR code. This is followed by the content of our QR code, in this case our string. Optionally, we can now specify the size of the QR code, if we do not want to define fixed values for height and width, we enter a 0 in each case. Now we can decide whether we want to rotate our QR code, which we do not want to do, so we also enter a 0 here. The next parameter is interesting for us again, because this is about the scaling. This should be at least 4 for a QR code that may later be printed. In our example, we are finished with the parameters, but you can also specify in your own projects whether, for example, the text under the barcode should be displayed for an EAN barcode and whether we want an encoding that differs from the standard UTF-8 encoding.
Set Variable [ $QR_Ref ; Value: MBS("Barcode.Generate"; "QRCode"; $Text; 0; 0; 0; 4) ]
However, this function does not yet return the image of our barcode, but a GMImage reference. We could then use GMImage references to edit the image further. However, we do not want to do this today and for this reason we now write the barcode to the container with GMImage.WriteToPNGContainer. We then have to release the resulting reference.
Set Field [ DoorOne::Barcode ; MBS("GMImage.WriteToPNGContainer"; $QR_Ref; "barcode.png") ] Set Variable [ $r ; Value: MBS("GMImage.FreeAll") ]
Now you can happily share your WIFI with your friends and family. I wish you lots of fun.
|👈 1 of 24 👉
You can download the example file here: Advent2023.fmp12.