remotely controlled gsm camera that sends pictures with ... · remotely controlled gsm camera that...

17
Elektor Intel Edison Challenge Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud

Upload: tranthuy

Post on 08-Mar-2019

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

Elektor Intel Edison Challenge

Remotely controlled GSM Camera that sends pictures with fractal

compression via SMS

Pierre Chabaud

Page 2: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

Abstract

I Global structure of the system II Edison Part III Reception Part Conclusion

Page 3: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

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 this place. Only SMS can be transmitted, MMS are too big and transmission fails every time. This is why I choose 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 the fewer 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 greedy power algorithm which is not possible with many micro-controllers.

Page 4: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

I Global structure of the system

1) Use of arduino IDE Why chosing Arduino? There are many IDE and languages to program the Intel Edison (Intel® XDK IoT Edition,

Arduino, Eclipse, Python …). I choose Arduino as I have already used C/C++ in several school

projects and so I have the basis to understand and code Arduino programms. Arduino’s IDE also

have a big community and 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 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 sends the wanted AT commands to the module according to 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; }

Page 5: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

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 that the user sends to get a picture have to start by 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 recover 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)

Page 6: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

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.

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).

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) that 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.

Page 7: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

FFmpeg use

2) Guillaume Priou base conversion contribution To send a file via SMS I chose to convert the compressed file into text and then to split it in 160 characters packets. To do this Mr. Guillaume Priou a University fellow developed a base64 and a base128 encoder/decoder algorithm for a University project and to help my project. The principle is to transform the binary that codes a file into text. A standard character is two of the power of seven coded. That means that we have 128 characters available. Unfortunately at least one quarter of these characters are badly transmitted in the serial line and the GSM modem doesn’t understand some others.

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"); }

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

Page 8: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

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.

3) Fractal compression

In contrast with 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 of 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

III Reception Part

1) Try of an Android Application Receiving the image on a mobile phone is the absolute objective of the project. To achieve this I received help of my friend Dennis 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. Doing operation with SMS on Android system 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.

Page 9: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

2) Hand rebuilding

To test the good running of 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.

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 the fewer 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.

@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);

}

Page 10: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global

Sources Sources attached

Pictures

Page 11: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global
Page 12: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global
Page 13: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global
Page 14: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global
Page 15: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global
Page 16: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global
Page 17: Remotely controlled GSM Camera that sends pictures with ... · Remotely controlled GSM Camera that sends pictures with fractal compression via SMS Pierre Chabaud . Abstract I Global