OneOS positioning function evaluation + development details

This article shares the official account of OneOS WeChat public. Positioning function evaluation + development details>.

In order to show you

OnePos location service capabilities

Reproduction of subway track

Took the subway for most of the day

I'm tired

You must see this video  

Click this jump demo video  

A small partner who wants to restore the development process one by one

You can see the following explanation

Absolute dry goods

Hands on Teaching (package meeting)  

Can't you find me  

Click this jump to explain the video

  Demonstrate video flow

Introduction to OnePos positioning platform

OnePos location service platform is a high-precision positioning platform that provides end-to-cloud / cloud to cloud services for intelligent hardware devices equipped with OneOS. It can choose a variety of positioning methods, and support auxiliary positioning means such as WiFi / base station / inertial navigation / GNSS analysis. At present, all services are completely free, and enterprise users can apply for a large amount of free commercial services according to their needs.

Learn more about reference Developer documentation: OnePos positioning - General introduction

OnePos location platform access

The steps to create a device on the OnePos location platform include the following:

Detailed operation instructions document reference Developer documentation: OnePos positioning - end to cloud Learn.  

OneOS positioning application development

Environmental preparation

At present, the OneOS code has been open source, and developers can go there OneOS warehouse perhaps OneOS official website Download.

OneOS cube is a command-line based development tool of OneOS operating system. It provides functions such as system configuration, project compilation and construction, package contribution and download, etc.

Download of oneos cube tool And instructions can be consulted Construction of oneos cube environment Learn.

Engineering configuration

  The components that OnePos location service depends on include: MQTT component, cJSON component and Molink component;

Use the graphical tool menuconfig.bat for project configuration:

1. MQTT components

  OnePos components communicate with OnePos platform through MQTT protocol. Developers can integrate MQTT components into their own applications through menuconfig graphical interface tool in OneOS Cube. The configuration of MQTT components is as follows:

For details, please refer to MQTT reference documents Understand

2. cJSON component

The interaction data between OnePos component and OnePos platform is encapsulated in JSON format. OneOS operating system provides the ability to create and parse JSON format data through cJSON component. The configuration of cJSON component is as follows:

For details, please visit cJSON Learning

3. Molink components

OnePos service principle uses the surrounding network environment data for positioning, and the ability to obtain network environment data and communicate with the platform is provided by Molink; this paper takes CAT1 module ML302 and WIFI module esp8266 as examples to obtain and communicate network data.

For detailed usage of Molink, please refer to MolinkAPI

four   OnePos component

  The OnePos location component needs to be used in conjunction with the OnePos location service platform to provide basic location capabilities for developers using the OneOS operating system;

At present, the service supports Wi Fi positioning, base station positioning and satellite positioning.

Note: when configuring the device Key of OnePos service, you need to MD5 (32-bit lowercase encryption) the device Key assigned by the positioning platform, and then configure the encrypted Key as the Key of OnePos component. Please refer to for detailed usage methods of OnePos component OnePos locate end-to-end documents

After configuring the above MQTT, cJSON and Molink components, use the command scons --ide=mdk5 in the oneos cube tool to update the MDK project settings.

The system runs successfully!

  Application example

Write the location application code of the following example for the trial of OnePos location service.

Source file: main.c

1.  #include <string.h>  
2.  #include <stdlib.h>  
3.  #include <stdio.h>  
4.  #include <os_task.h>  
5.  #include <os_dbg.h>  
6.  #include <os_errno.h>  
7.  #include <drv_gpio.h>  
8.    
9.  #include <onepos_interface.h>  
10.    
11.  #ifdef OS_USING_ST7789VW  
12.  #include "cmcclogo.h"  
13.  #include "oneposimage.h"  
14.  #include "st7789vw.h"  
15.    
16.  #define CMCC_LCD_TIME_ROW_SP 65  
17.  #define CMCC_LCD_TIME_ROW_H 50  
18.  #define CMCC_LCD_TIME_LCOLUMN_SP 65  
19.  #define CMCC_LCD_TIME_RCOLUMN_SP 110  
20.    
21.  #define SHOW_COLOR_RED 0xFA27  
22.  #define SHOW_COLOR_GREEN 0x1546  
23.  #define SHOW_COLOR_YELLOW 0xFD20  
24.    
25.  static void oneos_lcd_show_startup_page(void)  
26.  {  
27.      /* show CMCC logo */  
28.      lcd_show_image(20, 50, 200, 61, gImage_cmcc);  
29.      lcd_show_image(20, 150, 200, 52, gImage_oneos);  
30.  }  
31.    
32.  static void oneos_lcd_show_position(void *arg)  
33.  {  
34.      char    *str                 = OS_NULL;  
35.      char    time_get_now[9]      = {0,};  
36.      time_t  now                  = {0,};  
37.      os_int32_t     j             = 0;  
38.      static char    lat_show[20]  = {0,};  
39.      static char    lon_show[20]  = {0,};  
40.      static onepos_pos_t pos_data = {0,};  
41.            
42.      lcd_clear(BLACK);  
43.      lcd_show_image(0, 0, 240, 240, gImage_onepos);  
44.    
45.      while(1)  
46.      {  
47.          /* Get position */  
48.          onepos_get_latest_position(&pos_data);  
49.            
50.          /* Get time */  
51.          now = time(OS_NULL);  
52.          str = ctime(&now);  
53.    
54.          snprintf(lat_show, 24, "%f", pos_data.lat_coordinate);  
55.          snprintf(lon_show, 24, "%f", pos_data.lon_coordinate);\  
56.            
57.          for(j = 11; j < 19; j++)  
58.          {  
59.              time_get_now[j - 11] = str[j];  
60.          }  
61.          time_get_now[8] = '\0';  
62.    
63.          lcd_set_color(SHOW_COLOR_RED, BLACK);  
64.          lcd_show_string(CMCC_LCD_TIME_LCOLUMN_SP + 30, CMCC_LCD_TIME_ROW_SP + CMCC_LCD_TIME_ROW_H * 0 + 3, 24,  time_get_now);  
65.          lcd_set_color(SHOW_COLOR_GREEN, BLACK);  
66.          lcd_show_string(CMCC_LCD_TIME_LCOLUMN_SP + 30, CMCC_LCD_TIME_ROW_SP + CMCC_LCD_TIME_ROW_H * 1 + 15, 24, lat_show);  
67.          lcd_set_color(SHOW_COLOR_YELLOW, BLACK);  
68.          lcd_show_string(CMCC_LCD_TIME_LCOLUMN_SP + 30, CMCC_LCD_TIME_ROW_SP + CMCC_LCD_TIME_ROW_H * 2 + 30, 24, lon_show);  
69.            
70.          os_task_mdelay(50);  
71.      }  
72.  }  
73.  #endif  
74.    
75.  /* defined the LED0 pin: PD12 */  
76.  #define LED0_PIN    GET_PIN(D, 12)  
77.    
78.  int main(void)  
79.  {  
80.      os_uint32_t count         = 0;  
81.      os_task_t  *lcd_show_task = OS_NULL;  
82.        
83.      os_kprintf("Enter main function, here is the onepos code!\n");  
84.        
85.      #ifdef OS_USING_ST7789VW  
86.      oneos_lcd_show_startup_page();  
87.      os_task_mdelay(500);  
88.      #endif  
89.        
90.      #ifdef PKG_USING_NTP  
91.      /* wait ntp sync */  
92.      extern time_t ntp_sync_to_rtc(const char *host_name);  
93.      ntp_sync_to_rtc(OS_NULL);  
94.      os_task_mdelay(500);  
95.      #endif  
96.        
97.      count = 1;  
98.      /* set LED0 pin mode to output */  
99.      os_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);  
100.        
101.      /* start onepos sever and wait once position */  
102.      while(ONEPOS_CLOSING == onepos_get_server_sta())  
103.      {  
104.          onepos_start_server();  
105.          os_task_mdelay(5000);  
106.      }  
107.      /* creat lcd show task */  
108.      lcd_show_task = os_task_create("lcd_show", oneos_lcd_show_position,  
109.                                      OS_NULL,   
110.                                      2048, OS_TASK_PRIORITY_MAX / 2 - 4, 50);  
111.        
112.      if (lcd_show_task != OS_NULL)  
113.      {  
114.          os_task_startup(lcd_show_task);  
115.      }  
116.        
117.      while (count++)  
118.      {  
119.          os_pin_write(LED0_PIN, PIN_HIGH);  
120.          os_task_mdelay(400);  
121.          os_pin_write(LED0_PIN, PIN_LOW);  
122.          os_task_mdelay(400);  
123.      }  
124.        
125.      return OS_EOK;  
126.  }

Header file: oneposimage.h

Baidu online disk:

[https://pan.baidu.com/s/1ZYIirm7aA4qbFyHYB2_yWw]  

[extraction code: ppad]

Directly replace main.c in basic engineering with the above demonstration program in the demonstration video;

Since the demonstration function includes the function of real-time time time display, NTP service needs to be used for time synchronization;

So configure the project again: start ntp service;

Then compile and burn the program;

Query device location information on OnePOS platform:

OneOS: OneOS is a lightweight operating system launched by China Mobile in the field of Internet of things. It has the characteristics of tailorability, cross platform, low power consumption and high security. It supports mainstream CPU architectures such as ARM Cortex-M/R/A, MIPS and RISC-V, is compatible with POSIX, CMSIS and other standard interfaces, supports the development of Python language and provides graphical development tools, which can effectively improve the development efficiency and reduce the development cost Cost, help customers develop stable, reliable, safe and easy-to-use Internet of things applications. Official website address: https://os.iot.10086.cn/

Tags: Python IoT

Posted on Mon, 29 Nov 2021 10:25:24 -0500 by greensweater