You are here

You are here

Page Example

Bluetooth Chat Sample Overview

The (Circle) Bluetooth Chat sample application demonstrates how you can send and receive data between 2 devices.

The following figure illustrates the main screens of the (Circle) Bluetooth Chat application.

Figure: (Circle) Bluetooth Chat screens

The main screen has 2 buttons for finding devices (Search friends) and creating a server (Wait a friend). The chat room screen is created with the [UI Sample] MessageBubble sample application.

Implementation

Client

To start the client application, click Search friends. The client draws its own layout (list of found devices) with the _search_layout_create() function.

While drawing the list, the application starts finding devices with the _discovery_start() function. Set the device discovery state changed callback, and the list updates whenever a new device is found.

If you click an item on the list, the application starts to bond with the target device, and requests to connect to the target server. When successfully connected with the target, the _socket_conn_state_changed_cb() function is called and the application moves to the chat room layout for chatting.

Server

To start the server application, click Wait a friend. The role of this application is to create a server for chatting, and wait for a client. Before drawing the proper layout, it checks whether the device is discoverable using the _server_create() function.

The server application also registers a callback for detecting the state of the socket connection. The callback function is the same as that of the client. The application creates a server, and when the socket connection is established, it moves to the chat room layout.

The chat room is created by calling the bt_chat_room_layout_create() function. The function draws the layout for chatting, and unsets and re-registers the callback for the connection state change. It also registers the data received callback. When the message is received from the target, the application makes a message bubble for the new message.