16
27/12/2015 1 Elektor Intel Edison Challenge Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud

Remotely controlled GSM Camera that sends ... - Elektor · 27/12/2015 1 Elektor Intel Edison Challenge Remotely controlled GSM Camera that sends pictures with fractal compression

  • Upload
    dodang

  • View
    233

  • Download
    1

Embed Size (px)

Citation preview

27/12/2015

1

Elektor Intel Edison Challenge

Remotely controlled GSM Camera that sends pictures with fractal compression via SMS

Pierre Chabaud

27/12/2015

2

Contents Abstract .................................................................................................................................. 3

I. Global structure of the system ......................................................................................... 5

1. Using the arduino IDE ................................................................................................... 5

2. Arduino GSM Shield modem ........................................................................................ 5

3. Usb webcam ................................................................................................................. 6

4. SDcard .......................................................................................................................... 7

5. Power supply ................................................................................................................ 8

II. Edison Part ...................................................................................................................... 9

1. FFMPEG Library and system() calls ............................................................................. 9

2. Making text from image files with base64 encoding ..................................................... 9

3. Fractal compression ................................................................................................... 11

III. Reception Part ............................................................................................................... 12

1. Creating an Android Application ................................................................................. 12

2. Hand rebuilding .......................................................................................................... 12

Conclusion ............................................................................................................................ 13

Sources ................................................................................................................................ 14

Pictures ................................................................................................................................ 15

27/12/2015

3

ABSTRACT

This project has been imagined to answer a need: transmit an image from my family cottage located in the mountains to my home which is in a big city, near Paris. The point is that no Internet connection is available in my family cottage. Only SMS can be transmitted, MMS are too big and transmission fails every time. This is why I chose to use the SMS service to get my image.

Then, the goal of the project is to have a local Intel Edison based system able to take pictures (with an Usb webcam) and to transfer them through as few SMS as possible. We will take advantage of having a Linux system and a powerful hardware to compress as much as possible the image with a greedy power algorithm that cannot be used with many micro-controllers.

USB webcam and the Edison hardware upper part

27/12/2015

4

ACKNOWLEDGMENTS

I thank Mr. Guillaume Priou for base encryption, and Mr. Denis Barlet for his help and advices during the realization of the Android application.

27/12/2015

5

I. GLOBAL STRUCTURE OF THE SYSTEM

1. Using the arduino IDE

Why choosing Arduino?

There are many IDE and languages to program the Intel Edison (Intel® XDK IoT Edition, Arduino, Eclipse, Python …). I chose Arduino as I have already used C/C++ in several school projects and so I have the background to understand and code Arduino programs. The world of Arduino’s IDE is a big community too and there exists a lot of code examples and libraries, which greatly helps when you don’t want to code low level functions in each part of a project. Finally, Arduino makes really easy the communication between the Arduino part and the Linux part with system calls that we will explain in a next chapter.

Arduino IDE Interface

2. Arduino GSM Shield modem

To send and receive SMS, I decided to use the Arduino GSM Shield. This is based on the Quectel M10 chip and communicates via serial link with the Intel Edison Arduino kit thanks to AT commands. Official libraries didn’t work with the Intel Edison, so I had to code C functions that send the relevant AT commands to the module, in compliance with the datasheet.

int ReceiveTextMessage() { Serial1.println("AT+CMGR=1"); //read the first message on the SIM delay(100); StrPosition = output.indexOf('Z'); order=(output.charAt(StrPosition + 1)-48)*10 + (output.charAt(StrPosition + 2)-48); return order; }

27/12/2015

6

In order to facilitate the reception of a SMS and identify if it is a fake or not, we fixed the rule that each order sent by the user to get a picture has to start with a ‘Z’. The order is in the range [0;99] so the program will look at the two following numbers in the char array, in order to retrieve the message.

The sending function is really basic. It takes a String for the message and a String for the phone number as parameters.

Arduino GSM Shield

AT commands of the GSM modem

3. Usb webcam

A big advantage of the Arduino Intel Edison Kit is its USB port that allows plugging USB OTG devices. To be recognized by Linux it is easier to have an UVC compatible webcam, as UVC drivers are preinstalled on the Edison and also because the program that catches a frame from a video stream (ffmpeg) is compatible with it.

Serial1.println("AT+CMGS=\"<phone number>\""); delay(1000); Serial1.print(message); delay(1000); Serial1.println((char)26); //the ASCII code of the ctrl+z is 26 (0x1A)

27/12/2015

7

USB webcam connected to the hardware

Detection of the USB webcam

4. SDcard

To keep a backup and to process, I found really interesting to use a micro-SD card. The 8Go SD card is able to save pictures for years.

During the project, the SD card was also really useful to transfer packets and files without using the Wifi.

SD card ready for use

27/12/2015

8

5. Power supply

To supply the system with an USB device plugged, it is obligatory to turn the switch toward the USB A connector. Then, the Arduino side is no longer available to program and, so an auto-launch Arduino sketch script is needed to autostart the Arduino program. In that case, the power supply has to come from the jack connector (9V 1A in this case).

To make the system portable we can also use a 9V battery

27/12/2015

9

II. EDISON PART

1. FFMPEG Library and system() calls

Wikipedia: FFmpeg is a free software project that produces libraries and programs for handling multimedia data.

I decided to use video4linux2 (v4l2), which is able with few parameters to save an image from a RAW video stream.

Thanks to Arduino’s system() calls, we are able to automate the process.

FFmpeg use

2. Making text from image files with base64 encoding (G. Priou)

To send a file via SMS, I chose to convert the compressed file into text and then to split it in 160 characters packets (i.e. the length of a SMS).

To do this, Mr. Guillaume Priou, a University fellow, developed a base64 algorithm and a base128 encoder/decoder algorithm for a University project and to contribute to my project. The base64 encoding is widely used due to its efficiency to transmit any type of data through the internet.

void getHDpicture() { system("./ffmpeg -s 640x480 -f v4l2 -i /dev/video0 -vframes 1 /media/sdcard/HQimage.jpeg"); } void getMDpicture() { system("./ffmpeg -s 320x240 -f v4l2 -i /dev/video0 -vframes 1 /media/sdcard/MQimage.jpeg"); } void getLDpicture() { system("./ffmpeg -s 240x180 -f v4l2 -i /dev/video0 -vframes 1 /media/sdcard/LQimage.jpeg"); }

27/12/2015

10

The principle is to transform a source file written in a binary format into a target text file.

The main point of the base 64 encoding is to translate/convert 3 bytes of binary data into 4 bytes of text data. The text characters to be used must be among the following list :

uppercase & lowercase letters, 0 to 9 digits, "+" and "/" symbols (64 characters, i.e. 26 possibilities).

The encoding process will replace 6 bits (from the image file so those bits have a binary form) with 1 byte, that is to say an ASCII character.

Connection between binary coded image file and encoded text file

As a consequence, the resulting text file is 33 percent bigger than the original file (we replaced 6 bits with 8 bits (i.e. 1 byte). In order to decrease the size of the text, we could use a base128 encoding. In this way, the text file is only 14 percent bigger than the original file. Unfortunately, the ASCII characters that are normalized on an international scale and that are usable for the purpose of the encoding are not numerous enough to find 128 characters. The proper functioning of the base128 encoding algorithm will depend on the systems used to process and transmit the text file.

For instance, we can use the following characters to encode the image file but those characters will not be properly transmitted anywhere in the world:

Unfortunately, at least one quarter of these characters are badly transmitted in the serial line and the GSM modem doesn’t understand some others.

Currently, we use the base 64 version that is working, and we are still studying and programming an intermediate base that will let us transmit more characters and so transmit more information in the same space.

String message = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ +/!#$%&()*,-.:;<®>?@[]^_`{|}~ÇüéâäàçêëèïîìÄÅÉæÆôöòûùÿÖÜøØ׃áíóúñÑ¿" ;

27/12/2015

11

3. Fractal compression

Contrary to a jpeg compression, a fractal compression is a lossy compression. The principle is to detect the redundancy in the image and to remove it as much as possible. Once all of the redundancy has been removed then no further compression is possible.

After testing several fractal compression algorithms, I found that it was really hard to have a good compression without having a degraded picture.

I finally studied Ghosh, S.K. and Mukhopadhyay, J (2004) project that converts few kinds of pictures and videos. Despite its age, it has given fairly good results on my computer. Unfortunately, I have not yet managed to carry onboard of the Edison.

Fractal commands

27/12/2015

12

III. RECEPTION PART

1. Creating an Android Application (D. Barlet)

Receiving the image on a mobile phone is the absolute objective of the project. To achieve this, I received help of my friend Denis Barlet to program an android application. The application had to receive SMS from a phone, copy and paste them into a text file and decode them.

Operating with SMS on Android systems is really badly documented and doing cursor operation is very hard.

Currently, the application is able to display all SMS received by a given phone number. We are still working on this app to make it working well.

2. Hand rebuilding

To test and check the image sender program, I have to manually copy/paste the SMS in a .txt file in order to do the base 64 decoding and then the fractal decoding.

@Override

public void onClick(View v){

//Get phone number

String pnumber = "address = " + "'" + edit1.getText().toString()+"'";

//Create Inbox box URI

Uri inboxURI = Uri.parse("content://sms/inbox");

// List required columns

String[] reqCols = new String[]{"_id", "address", "body"};

// Get Content Resolver object, which will deal with Content Provider

ContentResolver cr = getContentResolver();

// Fetch Inbox SMS Message from Built-in Content Provider

Cursor c = cr.query(inboxURI, reqCols, pnumber, null, null);

// Attached Cursor with adapter and display in listview

adapter = new SimpleCursorAdapter(this, R.layout.row, c, new

String[]{"body", "address"}, new int[]{R.id.lblMsg, R.id.lblNumber});

listmes.setAdapter(adapter);

}

27/12/2015

13

CONCLUSION

To conclude, this project is a new approach of connected devices. Nowadays, people often use internet to transmit data and I had the opportunity to prove that using SMS is possible to transmit images when no internet is available. The image resulting from as few SMS (50) as possible is a grayscale image with a size of 240x180. Nevertheless, the advantage of this system is that the GSM/UMTS network is available quiet everywhere in France and in the world. Thanks to my project, you can see what’s happening far away.

27/12/2015

14

SOURCES

Sources attached

27/12/2015

15

PICTURES

27/12/2015

16