cesanta / mongoose-os

Mongoose OS - an IoT Firmware Development Framework. Supported microcontrollers: ESP32, ESP8266, CC3220, CC3200, STM32F4, STM32L4, STM32F7. Amazon AWS IoT, Microsoft Azure, Google IoT Core integrated. Code in C or JavaScript.
https://mongoose-os.com
Other
2.51k stars 432 forks source link

mos has no javascript UART and SPI APIs? and RPCs? #191

Closed aifer2007 closed 7 years ago

aifer2007 commented 7 years ago

mos has no javascript UART and SPI APIs? and RPCs?

aifer2007 commented 7 years ago

I make my own uart js api for ESP32.

api_uart.js: let Serial = { // setStdout: ffi('int mgos_set_stdout_uart(int)'), setDebug: ffi('int mgos_init_debug_uart(int)'), write: ffi('int mgos_uart_write(int, char *, int)'), enableWrite: ffi('void mgos_uart_set_write_enabled(int, bool)'), isInited: ffi('int mgos_uart_is_inited(int)'), };

in mos.yml: ffi_symbols:

and then, in init.js: // Load Mongoose OS API load('api_timer.js'); load('api_gpio.js'); load('api_uart.js');

let uartNo = 1; Serial.setDebug(uartNo); // baut: 115200 let str = "Hello from ESP32-Serial: " + JSON.stringify(uartNo) + "\r\n"; let isInited = Serial.isInited(uartNo);

// Blink built-in LED every second let PIN = ffi('int get_led_gpio_pin()')(); // Helper C function that returns a // built-in LED GPIO GPIO.set_mode(PIN, GPIO.MODE_OUTPUT); Timer.set(1000 / milliseconds /, 1 / repeat /, function(pin) { let value = GPIO.toggle(pin); print(value ? 'Tick' : 'Tock'); print(isInited); print(Serial.write(uartNo, str, str.length)); }, PIN);

It works well.

I can receive the string on my notebook with a UART-USB converter(FT232)。

serial

aifer2007 commented 7 years ago

on ESP32, the UART2 is not available yet.

And the pins of a UART can't be assigned by programmer.

cpq commented 7 years ago

RPC api has been added

https://mongoose-os.com/video-tutorials.html#video6

cpq commented 7 years ago

Working on UART API now.

aifer2007 commented 7 years ago

That's great!

cpq commented 7 years ago

Done. https://mongoose-os.com/docs/#/js-api/api_uart.js/

aifer2007 commented 7 years ago

Great!

发自我的 iPhone

在 2017年4月10日,上午12:27,Sergey Lyubka notifications@github.com 写道:

Done. https://mongoose-os.com/docs/#/js-api/api_uart.js/

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.