Configuration from Text File | Telit Cinterion IoT Developer Community
November 2, 2016 - 1:30pm, 4329 views
Hello.
I'm developing a project in which I use the BG5ST to establish a webserver that handles simple http requests.
I would like to know if it possible, and how, to configure the parameters of the socket I use in my java file with a text file so that it is easily modified not needing to open a code editor.
Thanks
Hello,
You can place your configuration parameters in the jad file and read them with getAppProperty(String key) method of the MIDlet class.
Or you can implement your own configuration file and access it with FileConnection API.
Example:
try {
FileConnection fconn = (FileConnection)Connector.open("file:///a:/somefile.txt");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (!fconn.exists())
fconn.create(); // create the file if it doesn't exist
fconn.close();
}
catch (IOException ioe) {
}
Regards,
Bartłomiej
I'm sorry but I'm not sure I understood what you explained.
So basically, I have a socket in which I establish the connection of BG5ST to the internet.
So basically what I want is to make a file in which I can define the variables port_,apn_, etc.
So, from what I understood, you're telling me I can upload a jad into bg5st via Module app in which I'll those variables charged with values, and to get those values I'll have to call the method getAppProperty?
What about the alternative? I would have to send the .txt with the configuration into module and call that "getAppProperty" method? Does the file need to follow some sort of format to be usable?
Sorry for the questions but I'm kind of new to this.
Thanks
You can add your variables to the jad file like below:
Port: 1000
APN: apn_name
And read them (inside the MIDlet class only) like:
apn_ = getAppProperty("APN");
In that case to change the values you will need to reinstall the MIDlet (it is copied to some hidden area during the installation so you don't have access to it). And there is no way to change these variables by the MIDlet.
In the alternative case you have to implement it on your own so it is up to you how you do it. You have the FileConnection API to access the file on the file system and the standard Java API's to read and parse the text.
In fact there is also another way - jsr280 API for XML if you prefer.
Regards,
Bartłomiej
Is there any detailed section of the manual dedicated to this matter or some sort of tutorial? The system is working properly with my java program and I'm kind of relutant on messing with the connection properties and mess all the system.
Hi,
Some examples,with the source code, can be found in the Knowledge Base.
Example with the parameters in the jad file:
https://iot-developer.thalesgroup.com/showcase/uart-ftp-pipe-example-java-midlet
Example using a external plain text file in the FFS:
https://iot-developer.thalesgroup.com/showcase/cinterion-ehs6-concept-board-and-windmill-java-demo-sensorlogic
Regards
ALopez
Somewhere over the rainbow!!! Looking for the Oz Land!!!
Hello ALopez.
First of all, many thanks for your answer and pointing out those two handy articles.
I've got a couple of questions,though.
I've noticed that the executable file, the .jad, is produced when you build and compile your java application. Still, I don't understand the way to acess that file in order to upload it into the BG5ST via the Module App. Is it stored somewhere when I compile my program? Is it a pack produced when I export my app? I'm kind of clueless.
In the second article they mention two .config files. Are those suppose to be uploaded in the same way that the .jad file? How am I supposed to link my program with that .config file an grab the variable values? Although the articles you kindly posted are interesting, the process is not described step-by-step which for a newbie like me (lol) is kind of difficult to follow.
Once again,
Many thanks.
Hello,
If you are using Eclipse you should choose Export and then Export MIDlet Package. The jad and jar files are created in the build folder. The jad is just a text file - there are some standard MIDlet variables and you can add youur own.
You need to upload the files to the module's file system - you can use MES application which you have probably installed - you can access it by clicking Module in the Windows explorer. The proper COM port ***** to be configured by right clicking the Module. After that the application ***** to be installed with AT^SJAM command.
If you decide to use the text files you need to decide where the files will be stored (main directory or some folder) and implement the access to the files in your application. You will also find some example how read and write the files here:
https://iot-developer.thalesgroup.com/tutorial/example-how-use-flash-fil...
I think that you should read the Java User's Guide document that covers the environment setup, creating and building the MIDlet application, running it from Eclipse or manually and much more. You can find one here: https://iot-developer.thalesgroup.com/documentation/cinterion%C2%AE-conc...
Regards,
Bartłomiej
Second example worked like a charm.
It's working!
Many thanks, Barlomiej and ALopez