Smart Cloud WebSocket realize IoT game

Source: Internet
Author: User

0. Introduction

I am in the final course of undergraduate design, do more interesting, while the recent internet of things is gradually hot, so share your work design process. The work is in the wit cloud the simplest STM32 core board routines, the use of the communication protocol is witty cloud-written smart cloud connection firmware, Web programming is also the websocket of the smart cloud Demo. I do is in the original core system to add do not step on the white block of the Internet of things game features. The implementation results are as follows:

Youku Video Address: http://player.youku.com/embed/XMzcyMzU0NjE0OA==

The effect is that on the Web page JavaScript do not step on the white block game display data via WebSocket sent to the smart Cloud control platform, and then the wit cloud issued to STM32, the realization of the Web game display and STM32 display synchronization (there will be a little network delay).

1. Realization of equipment

1) SMARKIT-ESP STM32 Core Board

2) Smart Cloud Platform

3) 0.96-inch OLED display (four-pin, IIC communication)

4) Smart Cloud WebSocket Demo plus simple don't step white block game JS

5) Burn Good wit cloud firmware ESP8266

2. Implement step 2.1 to write STM32 hardware program

Modify your device information in the Wit cloud Protocol header file (acquired after the smart cloud creates the device):

    

Add do not step on the white block data macro definition, in this I use two uint8_t type data to transmit, because the display of the white block location of a total of 16, originally intended to use uint16_t transmission, but need to modify the full set of smart Cloud upload package format, so I just split two pieces of data transfer, The macro definition is designed to facilitate later programming:

    

Add data to the transport package structure that does not step on the white block:

    

Game scheduling function Implementation:

    

Game Timing Display

The event response function after the acquisition of the Wit Cloud packet is added:

      

2.2 Pages don't step on white block JS and wit cloud websocket realization

The specific implementation is to use the smart cloud directly provided by the WebSocket of the demo add do not step on the white Block JS code, the actual code is a bit large, here is not detailed explanation, follow-up will be at the end of the text to give a complete set of code.

  

2.3 Deploying products in smart Cloud

The first is to create your own product in the smart cloud, which is the access key for the smart cloud hardware.

To add a data node:

2.4 Configuring page control information

It still takes a lot of steps to control access to the smart cloud with a Web page, because to keep the device secure, you must implement user-device bindings that bind the Chitian that need to get a response. Specific user and device bindings reference Smart Cloud official information: http://docs.gizwits.com/zh-cn/UserManual/UseWebsocket.html

The results of the configuration success are as follows:

2.5 Websocke Connection Device

 

2.6 Testing the Internet of things don't step on the white block game

3, the project complete source code

Since there is no good file sharing port in the blog park, I will use the file share of CSDN next door: https://download.csdn.net/download/vitcou/10541825

If someone wants to use other STM32 to achieve this effect, it is necessary to configure the smart cloud connection, I am directly using the ESP8266 to burn the smart cloud firmware to achieve.

Smart Cloud WebSocket realize IoT game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.