Giter VIP home page Giter VIP logo

zephyr.js's Introduction

DISCONTINUATION OF PROJECT.

This project will no longer be maintained by Intel.

Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project.

Intel no longer accepts patches to this project.

If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project.

JavaScript* Runtime for Zephyr™ OS

The JavaScript* Runtime for the Zephyr™ OS project (ZJS for short) provides an IoT web runtime environment with JavaScript APIs for the Zephyr operating system, based on the JerryScript engine. It is intended for systems with little memory where Node.js with V8 is too big.

This code requires a local copy of JerryScript and Zephyr OS source. We will upstream patches to those projects as appropriate, but this repo is for everything else.

Index

Getting Started

ZJS should work on most of the boards supported by the Zephyr OS, though it does have higher memory / flash requirements so it won't work on the very smallest boards. So far we've had our hands on these boards: Arduino 101 / tinyTILE, FRDM-K64F, nRF52-DK, Arduino Due, NUCLEO-F411RE, STM32F4DISCOVERY, 96Boards Carbon, and OLIMEX STM32 E407. Please do try it with any other boards Zephyr supports and let us know what works and what doesn't.

Up until recently, the Web IDE which makes ZJS development very easy only worked on Arduino 101. So the following instructions are still specific to Arduino 101 but we'll try to update them soon; until then please ask for help on IRC if you have questions about working with a particular board.

This section will walk you through building and running your first ZJS application on Arduino 101*.

Prerequisites

Developing with the Web-based IDE

The easiest way to develop your JavaScript app on Zephyr is using our Web-based IDE which allows you to write JS apps on the fly in our online editor and upload them directly to the Arduino 101 board through WebUSB. Please follow our Zephyr Project JavaScript & WebIDE Tutorial to get started with the Web IDE and check out the ashell guide for more advanced usages.

Zephyr Project JavaScript & WebIDE Tutorial

Classical 'Build and Flash' development

Initial Setup

Windows and OSX users: These instructions are for Ubuntu 16.04. Be sure to also consult Zephyr Project's Getting Started documentation for Windows or OSX.

Install dependencies

First, install these packages that you will need beyond those installed by default with Ubuntu:

sudo apt update
sudo apt install cmake dfu-util git python3-yaml screen uglifyjs

Note: python3-yaml is a recent requirement for the frdm-k64f build due to a change in Zephyr, so it could be left out currently if you don't use k64f. Before that, for a while python-yaml was needed when the script was using Python 2.

You may also need to install pip3 to get pyelftools:

$ sudo apt install python3-pip
$ sudo pip3 install pyelftools

Clone the ZJS repo

Next, clone this git repo:

git clone http://github.com/intel/zephyr.js.git

Check out the desired version

If you want to use a stable release version, the latest is 0.5:

git checkout v0.5

If you do nothing and remain on master, you will be looking at the very latest changes which may have regressions or instability. You can read the version file in the root of the source tree to see what version you're on. If you're on the master development branch it will just say 'devel'.

Install the Zephyr SDK

Download the latest Zephyr SDK, then:

chmod +x /path/to/zephyr-sdk-<VERSION>-setup.run
sudo /path/to/zephyr-sdk-<VERSION>-setup.run

Follow the prompts, but the defaults should be fine.

Set up Zephyr SDK environment variables

Add the following two lines to your ~/.bashrc. If you installed your Zephyr SDK elsewhere, adjust as needed.

export ZEPHYR_GCC_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk

Then source the .bashrc :

source ~/.bashrc

Join the plugdev group

Add your user to the plugdev group with this command:

sudo usermod -a -G plugdev USERNAME

Add udev rules

Copy these two files into your /etc/udev/rules.d directory (/etc/udev.rules for Ubuntu 14.04):

Then run this command:

sudo udevadm control --reload-rules

This should cause your /dev/tty* entries to have the plugdev group, which will let you use them without root privileges. Otherwise, you will have to run some of the following commands with sudo.

Shell setup

Whenever you open a new terminal to work with this repo, you need to set up environment variables.

Set up ZJS environment variables

First, the ZJS variables:

cd zephyr.js
source zjs-env.sh

Get source dependencies

Next, this command will check out additional git repos into the deps/ subdirectory, if you haven't done so before:

make update

(If this is the first time you've run this, will see an error.)

Set up Zephyr OS environment variables

As the previous command will complain, you need to set up some Zephyr OS environment variables, too. Here's the right way to do that:

source deps/zephyr/zephyr-env.sh

Note: cmake 3.8.2 or later is required, and your system might install an older version, if this is the case, you'll have to manually install the latest version of cmake:

$ mkdir $HOME/cmake && cd $HOME/cmake
$ wget https://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.sh
$ yes | sh cmake-3.8.2-Linux-x86_64.sh | cat
$ echo "export PATH=$PWD/cmake-3.8.2-Linux-x86_64/bin:\$PATH" >> $HOME/.zephyrrc
$ source $ZJS_ROOT/deps/zephyr/zephyr-env.sh
$ cmake --version

Build and Flash

x86 application image and ARC support image

Now you're ready to build the x86 and ARC images. The x86 image includes the JerryScript engine and the ZJS runtime support, along with your JavaScript application, and the ARC support image acts as a helper library that channels some of the data needed from the ARC processor to the x86 processor.

Note: you'll need to build both the x86 and ARC images with the same JS file so the required sub-modules are enabled on both images.

You can build both with a single command:

make JS=samples/TrafficLight.js

The JS= argument lets you provide the path to your application. The TrafficLight sample is a good first choice because you don't need to wire up any additional hardware. It just blinks onboard LEDs on your Arduino 101. Also, for many of the samples you will want to hook up the serial console (see below), but for this one it's not really needed.

Then connect the Arduino 101 to your host with a USB A/B cable. Press the Master Reset button on the Arduino 101 and within a few seconds type:

make dfu

This will flash both the images to the device using the dfu-util program.

If you get a permission error, make sure you followed the plugdev group instructions above for this user. You shouldn't need to run this command with sudo.

After this flashing completes successfully, reboot the device with the Master Reset button to start the application. After a few seconds the onboard LEDs should start cycling.

You have built and run your first ZJS application!

If you want to make changes to the application, or run a different .js sample, you just need to repeat the steps the desired JavaScript filename.

Next steps

Set up serial console

Without the serial console set up, you won't be able to see error messages and other output from your ZJS application. To hook up the serial console, you need a USB to TTL Serial Cable, such as the TTL-232R-3V3. On that particular cable, you wire the black wire to ground on the Arduino 101 board, the orange wire to GPIO pin 0 (RX), and the yellow wire to GPIO pin 1 (TX). The other three are unused.

When you plug this in, the device should show up as something such as /dev/ttyUSB0. You can then use the screen command to connect to the device with a command such as this:

watch screen /dev/ttyUSB0 115200

The watch utility will restart screen when you disconnect and reconnect your Arduino 101, so you shouldn't miss anything. You can leave a dedicated terminal running to watch the output.

In screen, you can scroll back the output with Ctrl-A, Esc, followed by PgUp/PgDn. Then Esc again to get back to the latest output (out of "Copy Mode").

Debugging

Debugging native C code

See Zephyr's supported boards documentation for information on debugging with a specific board. For the Arduino 101, ZJS has special make targets: use the commands make adebug and make agdb in two separate terminals to connect to the device with a debugger. Then you can set breakpoints such as b main and run to start debugging as usual with gdb.

Debugging JavaScript code

JerryScript has a built-in remote debugger which allows debugging JavaScript programs. At the moment only a Websocket-based implementation is provided by JerryScript which transmits messages over TCP/IP networks, but it currently only supports ethernet, so you'll need to run it on a board that has ethernet support, for example, the FRDM-K64F or Linux.

To enable the remote debugger for a particular JS application:

make BOARD=frdm_k64f DEBUGGER=on JS=xxx.js

When you flash and run the JS application, it will start in debugging mode, running on 192.168.1.101:5001, and you will see the following on serial output:

Debugger mode: connect using jerry-client-ws.py

Waiting for client connection

you might need to add a route on your PC to connect to the network if you are connecting the board directly to your PC:

ip route add 192.168.1/24 dev eno1

Then you can use the jerryscript command line or html client to connect to the debugger to debug your JS application:

python jerryscript/jerry-debugger/jerry-client-ws.py --display 10 192.168.1.1

In the client, type 'help' to get a list of debugger commands, such as adding breakpoints, stepping through JS sources, etc.

Alternatively, we've created a client that integrates with Chome DevTools, which lets you use the Chrome's built-in debugger to connect and you can use it to set breakpoints and step through source from all within the browser. Please see installation instructions on how to set it up from here

Debugging JavaScript code on Linux:

To enable the remote debugger on Linux:

make BOARD=linux DEBUGGER=on
outdir/linux/release/jslinux app.js --debugger

It will then be run on debugger mode waiting for client connection, you can then in another terminal, you can connect to it by running the python client in JerryScript:

python jerryscript/jerry-debugger/jerry-client-ws.py --display 10 localhost

Additional details

See below for a few more tips, such as increasing the space available for your application on the Arduino 101, or how to use ZJS with the FRDM-K64F.

Getting more space on your Arduino 101

Arduino 101 comes with a 144K X86 partition, but we're able to use more space by telling Zephyr there is more space and then splicing the images we flash to the device. You can control this with the ROM= flag to make. So if you want to allocated 256KB for x86, use ROM=256.

You can also just build without it until you see a message like this:

lfiamcu/5.2.1/real-ld: region `ROM' overflowed by 53728 bytes

That implies you need an extra 53K of space, so you could try passing ROM=200. If it's the ARC image that needs more space, you should decrease the ROM you're passing instead.

Note: Earlier, we would physically repartition the device and install a new bootloader that knew about it. This is no longer necessary, so if you have such a device you should restore it to factory condition with the 256-to-144 flashpack.

You can also influence the amount of RAM allocated to the X86 side with a new RAM= argument. Here the default is 55 but it can theoretically go as high as 79 if ARC was disabled; realistically up to maybe 75 or so depending on how few modules you require in the ARC build.

The RAM and ROM sizes being used are now displayed at the top of the make output when you do build for Arduino 101.

JS Minifier

To save space it is recommended to use a minifier. In convert.py, the script used to encode your JS into a source file, we use uglifyjs. If you didn't install this earlier, you can do so with the command:

sudo apt install node-uglify

Other HW Platforms

nRF52 Platform

This is an experimental ZJS platform and has not been tested. There should be no expectation that any given sample/test/application will work at all on this platform. The good news is that there have been ZJS networking samples run on the nRF52 board with success therefore we mention it here so anyone can try it out and contribute fixes to anything that does not work, potentially getting it stable enough to adopt as a supported board in the future. The nRF52 board we have tested is nRF52 DK (nrf52_pca10040). Please see Zephyr's project page to see the supported nRF5x variant boards, since each board will have different instructions to flash. To flash to the nRF52 DK, you'll need to downloand and install the JLink Software and Documentation Pack and the nRF5x command-line tools.

See the Zephyr docs for general information about running Zephyr OS on the nRF52.

Connecting to serial output is quite similar to the Arduino 101, except the nRF52 will have an ACM port rather than USB. You can connect with minicom by doing:

minicom -D /dev/ttyACM0

Building is the same as any other ZJS platform, just use nrf52_pca10040 as the BOARD name:

make JS=samples/HelloWorld.js BOARD=nrf52_pca10040

You should now have a Zephyr binary in outdir/nrf52_pca10040/. You can flash it to the nRF52 DK board with the nRF5x command line tools:

  1. Connect the micro-USB cable to the nRF52 DK and to your computer and turn on the power switch.

  2. Erase the flash memory in the nRF52832:

$ nrfjprog --eraseall -f nrf52
  1. Flash the application using the nrfjprog tool:
$ nrfjprog --program outdir/nrf52_pca10040/zephyr.hex -f nrf52

You should see the lights flashing on the nRF52 board. When it stops you can reset the board and you should see your application output on /dev/ttyACM0. If you don't see any output, try pressing the BOOT/RESET button next to the power switch to boot it again.

From here the device can be connected with BLE to a Linux machine as you do with an Arduino 101.

FRDM-K64F Platform

See the Zephyr docs for general information about running Zephyr OS on the FRDM-K64F.

The instructions below assume Ubuntu 14.04 on the host PC.

Connect a micro-USB cable from the device to your PC.

If you hit the Reset switch and wait about five seconds, you should be able to start up a serial console. Either:

screen /dev/ttyACM0 115200

or

minicom -D /dev/ttyACM0

(I typically had to try either command several times before it would work.) The benefit of minicom is it will keep running even if you unplug the cable and then plug it back in later.

Check your dmesg output or watch your /dev directory to know what device it shows up as.

Then, follow these instructions to update your firmware.

Next, you can try to build ZJS for the platform:

make BOARD=frdm_k64f JS=samples/HelloWorld.js
cp outdir/frdm_k64f/zephyr/zephyr.bin /media/<USERNAME>/MBED/

After you copy the new .bin file to that directory, the device will reboot, blink an LED quickly as it writes the image, and then you should see the device reconnect as a USB storage device to your PC. Then you can press the Reset button to run the Zephyr image. You should see "Hello, ZJS world!" output on the serial console in less than a second.

If something doesn't work, you may want to establish that you're able to upload the K64F hello world application.

Then, you could try the Zephyr OS hello_world sample to narrow down the problem:

cd deps/zephyr/samples/hello_world/
mkdir build && cd build
cmake -DBOARD=frdm_k64f ..
make
cp zephyr/zephyr.bin /media/<USERNAME>/MBED/

Using the same procedure as above, once you hit Reset you should see "Hello World!" within a second on your serial console.

ST STM32F4DISCOVERY Platform

See the Zephyr Project Wiki for general information about running Zephyr OS on the STM32F4DISCOVERY.

Building is the same as any other ZJS platform, just use stm32f4_disco as the BOARD name:

make BOARD=stm32f4_disco ide

You should now have a Zephyr binary in outdir/stm32f4_disco/. You can flash it to the STM32F4DISCOVERY board with the openocd:

  1. Connect the Mini USB cable from the device(CN1) to your PC.

  2. Connect a micro-USB cable from the device (CN5) to your PC.

  3. Flash the application using the following command:

make BOARD=stm32f4_disco flash

You should see the lights flashing on the STM32F4DISCOVERY board. When it stops you should see WebIDE url notification from Chrome.

From here the device can be connected with WebIDE and upload JS code to the device.

OLIMEX-STM32-E407 Platform

See the Zephyr Project Wiki for general information about running Zephyr OS on the OLIMEX-STM32-E407.

Building is the same as any other ZJS platform, just use olimex_stm32_e407 as the BOARD name:

make BOARD=olimex_stm32_e407 ide

You should now have a Zephyr binary in outdir/olimex_stm32_e407/. You can flash it to the OLIMEX-STM32-E407 board with the openocd:

  1. Connect the ST-Link USB dongle to your host computer and to the JTAG port of the OLIMEX-STM32-E407 board.
  2. Connect the Mini USB cable to the device(OTG1 near LAN connector) to your PC.
  3. Flash the application using the following command:
make BOARD=olimex_stm32_e407 flash

You should see the lights flashing on the ST-Link USB dongle. When it stops you should see WebIDE url notification from Chrome.

From here the device can be connected with WebIDE and upload JS code to the device.

Running the JS app on Linux or Mac

Building and running on Linux

In addition to Zephyr there is a "linux" target which does not use Zephyr at all and instead uses the host OS. This can be built on Linux or MacOS using the command:

make BOARD=linux

The executable will be outputted to outdir/linux/<variant>/jslinux. Where <variant> is either debug or release. This is specified the same as the Zephyr target by passing in VARIANT= when running make. The default is release.

Note: To build on MacOS using BOARD=linux, see instructions in the next section.

What makes the linux target convenient is that a JS script does not have to be bundled with the final executable. By default samples/HelloWorld.js will be bundled but you can always just pass in a script on the command line when running jslinux e.g.:

./outdir/linux/release/jslinux samples/Timers.js

If a script is passed in on the command line it will take the priority over any script bundled with the executable (using JS=).

By default jslinux will exit when there are no pending events but if this is not desired, there are two flags which can be used to cause jslinux to run longer (or forever). The first is the --noexit flag. If this flag is used, jslinux will run indefinitely. The second flag (-t) will cause jslinux to run until a specified timeout (in milliseconds) is met. This flag can be used like:

./outdir/linux/release/jslinux -t <ms>

It should be noted that the Linux target has only very partial support to hardware compared to Zephyr. This target runs the core code, but most modules do not run on it, specifically the hardware modules (AIO, I2C, GPIO etc.). There are some modules which can be used though like Events, Promises, Performance an OCF. This list may grow if other modules are ported to the Linux target.

Building and running on MacOS

Mac support is still limited at this point. As Zephyr does not provide the SDK/toolchain to compile on MacOS natively, you will have to build your own or use a 3rd-party toolchain. Currently the targets we support building on Mac are "linux", "qemu_x86", with limited support for "arduino_101" and "frdm-k64f" boards. You'll need to have a recent version of MacOS and XCode command line tools from App store to get you started. Depending on your system setup and target, you might have to perform additional steps, but if you run into build issues, you should first make sure that you can build Zephyr native apps on Mac using the toolchain you installed. Once you verify that it works, then our project should also build and link correctly, but we'll try to update the document as we find these kinds of issues. Currently we enable Travis CI to build the linux target only against a recent version of MacOS (10.12) and XCode Command Line Tools (provided by XCode SDK) for sanity check purposes.

Set up

The basic requirement for building Zephyr boards is that you'll need to install and setup the correct cross-compiler toolchain on your Mac for the boards you are trying to build. You need to install crosstool-ng, which allows you to build the x86 images you can run on QEMU, and for Arduino 101, you need to install the ARC compiler, which can be found by installing the Arduino IDE for Mac, this is used to build the ARC support image.

Requirements:

  • MacOS 10.12 (Sierra) or later
  • XCode Command Line Tools: 8.1 or later (clang)
  • Python: 2.7 or later
  • Homebrew
  • Crosstool-ng
  • ARC cross-compiler (for building Arduino 101)
  • Python-yaml

First, make sure you have Homebrew installed, instructions here, and then install the following brew packages:

brew install cmake ninja dfu-util doxygen qemu dtc python3 gperf

Install tools needed for building the toolchain:

brew install binutils gawk gettext help2man mpfr gmp coreutils wget
brew tap homebrew/dupes
brew install grep --with-default-names
brew install gnu-sed

If you have installed these packages before, make sure you update to the latest:

brew update
brew upgrade

Next, you'll need to update to the latest MacOS and install/upgrade to the latest XCode Command Line Tools (we tested MacOS Sierra 10.12 and XCode 9.1) from App store.

To install XCode Command Line Tools, open a terminal and type the following, it should pop up a window to ask you to install the tools:

xcode-select --install

You'll then set up the environment variables:

cd zephyr.js
source zjs-env.sh
make update
source deps/zephyr/zephyr-env.sh

Install Zephyr dependencies:

curl -O 'https://bootstrap.pypa.io/get-pip.py'
sudo python ./get-pip.py
rm get-pip.py
cd deps/zephyr
pip3 install --user -r scripts/requirements.txt

Build Kconfig in $ZEPHYR_BASE/build and add it to path

brew install gtk+ libglade
cd $ZEPHYR_BASE
mkdir build && cd build
cmake ../scripts
make
echo "export PATH=$PWD/kconfig:\$PATH" >> $HOME/.zephyrrc
source $ZEPHYR_BASE/zephyr-env.sh

Note: You only need to do this once after cloning the git repository.

Building Linux target

You can build the "linux" target on MacOS using BOARD=linux, follow instructions for "Building and running on Linux". This will create the jslinux ouput.

Building QEMU and Arduino 101 targets

You can build QEMU with BOARD=qemu_x86 and Arduino 101 with BOARD=arduino_101, you'll need to install crosstool-ng (1.23 or later) and ARC compiler from Arduino IDE.

Install crosstool-ng:

wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.23.0.tar.bz2
tar xvf crosstool-ng-1.23.0.tar.bz2
cd crosstool-ng-1.23.0/
./configure
make
make install

After installing crosstool-ng, create and mount the image using our script osxmountzephyr.sh:

osxmountzephyr.sh

Once you've created the image the first time, you can subsequently re-mount and un-mount the images with:

hdiutil mount CrossToolNG.sparseimage
diskutil umount force /Volumes/CrossToolNG

This will create an image mounted under /Volumes/CrossToolNG. You can then configure crosstool-ng:

cd /Volumes/CrossToolNG
mkdir build
cd build

In the Zephyr kernel source tree we provide configurations that can be used to preselect the options needed for building the toolchain.

The configuration files can be found in $ZEPHYR_BASE/scripts/cross_compiler/.

Currently the following configurations are provided:

i586.config: for standard ABI, for example for Galileo and qemu_x86 iamcu.config: for IAMCU ABI, for example for the Arduino 101

(replace i586.config with iamcu.config for Arduino 101)
cp ${ZEPHYR_BASE}/scripts/cross_compiler/i586.config .config
ct-ng oldconfig

After you are done, edit the generated .config, and make sure you have these settings, or you will run into build errors later:

...
CT_LOCAL_TARBALLS_DIR="/Volumes/CrossToolNG/src"
# CT_SAVE_TARBALLS is not set
CT_WORK_DIR="${CT_TOP_DIR}/.build"
CT_BUILD_TOP_DIR="${CT_WORK_DIR}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
CT_PREFIX_DIR="/Volumes/CrossToolNG/x-tools/${CT_TARGET}"
CT_INSTALL_DIR="${CT_PREFIX_DIR}"
# Following options prevent link errors
CT_WANTS_STATIC_LINK=n
CT_CC_STATIC_LIBSTDCXX=n
...

If you experience issue building Cross GDB at the end, you can ignore it or comment out the following:

# CT_GDB_CROSS=y

Now you can build crosstool-ng. It will take 20~30 mins:

ct-ng build

When finished, you should have the toolchain setup in /Volumes/CrossToolNG/x-tools directory. now go back to the project's directory and set some environment variables:

export ZEPHYR_GCC_VARIANT=xtools
export XTOOLS_TOOLCHAIN_PATH=/Volumes/CrossToolNG/x-tools

To use the same toolchain in future sessions, you can set the variables in the file $HOME/.zephyrrc. For example:

cat <<EOF > ~/.zephyrrc
export XTOOLS_TOOLCHAIN_PATH=/Volumes/CrossToolNG/x-tools
export ZEPHYR_GCC_VARIANT=xtools
EOF

For a new environment, create a symlink for Python2.7:

ln -s /usr/bin/python2.7 /usr/local/bin/python2

Now, you can build and run on QEMU using this command:

make JS=samples/HelloWorld.js BOARD=qemu_x86 qemu

You should see output (To exit from QEMU enter: 'CTRL+a, x') :

SeaBIOS (version rel-1.11.0-0-g63451fca13-prebuilt.qemu-project.org)
Booting from ROM..
Hello, ZJS world!

Note: There are currently some cmake issues and crosstool-ng using the latest Zephyr (1.10.0), and here are some of the work-arounds.

If you see an compile error like:

No such file or directory: CMAKE_READELF:
'/Volumes/CrossToolNG/x-tools/i586-zephyr-elfiamcu/bin/i586-zephyr-elfiamcu-readelf'

edit ${ZEPHYR_BASE}/cmake/toolchain-xtools.cmake and change the line:

set(CROSS_COMPILE_TARGET_x86 i586-zephyr-elfiamcu)

to

set(CROSS_COMPILE_TARGET_x86 i586-zephyr-elf)

and append the following line:

set(TOOLCHAIN_INCLUDES ${TOOLCHAIN_HOME}/${CROSS_COMPILE_TARGET}/${CROSS_COMPILE_TARGET}/include)

If you see a QEMU error like, it could be the qemu package on your system were installed to /usr/local/share/ :

qemu-system-i386: -L -bios: Could not open 'bios.bin': No such file or directory

edit ${ZEPHYR_BASE}/boards/x86/qemu_x86/board.cmake and change the line:

-L ${QEMU_BIOS}

to

-L /usr/share/local/qemu

To build for Arduino 101, you'll need to download the latest Arduino IDE here. Once you have the IDE installed, open the IDE and click on Tools->Board->Board Manager, and install the latest version of the board support package "Intel Curie Boards". This will install the arc-elf compiler located in the following directory:

$HOME/Library/Arduino15/packages/Intel/tools/arc-elf32/

Then copy the compiler to where you installed the crosstool-ng toolchain:

cp -pR $HOME/Library/Arduino15/packages/Intel/tools/arc-elf32 /Volumes/CrossToolNG/

The compiler is in a subdirectory, such as 1.6.9+1.0.1. You'll need to set this path in cmake to make to find the right bin file.

Edit deps/zephyr/cmake/toolchain-xtools.cmake, and change the following:

set(CROSS_COMPILE ${TOOLCHAIN_HOME}/${CROSS_COMPILE_TARGET}/bin/${CROSS_COMPILE_TARGET}-)

to

set(CROSS_COMPILE /Volumes/CrossToolNG/arc-elf32/1.6.9+1.0.1/bin/arc-elf32-)

You can now build for Arduino 101 (without setting BOARD=, it builds arduino_101 by default)

make JS=samples/HelloWorld.js

Note: There's currently a bug that you'll run into a build issue when buiding for the Arduino 101 using the latest Zephyr (1.10.). See bug

Other targets like FRDM-K64F or possibly other ARM boards on Mac

These also have limited support currently. The requiremenet is that you'll need to install the GCC ARM Embedded cross compiler here

After you download it, set these environment variables:

export GCCARMEMB_TOOLCHAIN_PATH="/Users/<USERNAME>/Downloads/gcc-arm-none-eabi-6-2017-q1-update"
export ZEPHYR_GCC_VARIANT=gccarmemb

Then you can build like this:

make JS=samples/HelloWorld.js BOARD=frdm_k64f CROSS_COMPILE=~/Downloads/gcc-arm-none-eabi-6-2017-q1-update/bin/arm-none-eabi-

For additional information, see here on how to setup third-party compilers.

Supported modules on Linux and Zephyr

See board summary for some basic comparison information about the boards we've tested on.

There is only partial support for modules on Linux compared to Zephyr. Any hardware specific module (I2C, UART, GPIO, ADC etc.) is not supported on Linux. Trying to run a Zephyr specific module on Linux will result in the JavaScript not running successfully. Below is a complete table of modules and target support. Some Zephyr targets listed are experimental and have not been fully tested. For this reason we have the following possibilities for support:

  • X - Supported
  • E - Experimental, not formally tested by QA but basic functionality verified.
  • NT - Not tested at all
  • Blank - Not Supported
Module Linux A101/tT K64F nRF52 Due F411RE STM32F4 OLIMEX E407 Carbon
HelloWorld X X X X X X X X X
ADC X X
BLE X X
Buffer X X X X X X X X X
Console X X X X X X X X X
Dgram X X
Event X X X X X X X X X
File System X X
GPIO X X
I2C X X
Net X X
OCF X X X NT
Performance X X X X X X X X X
PME X
PWM X
Sensor X X
Timers X X X X X X X X X
UART X NT
WebSocket X X
WebUSB X

Networking with QEMU

QEMU has support for networking features that can be tested on your Linux desktop. To do this you will need to build a separate "net-tools" project:

git clone https://github.com/zephyrproject-rtos/net-tools
cd net-tools
make

If the build fails, you may need to install the libpcap-dev package:

sudo apt install libpcap-dev

Open up 2 terminals to run the tools from the net-tools directory: Terminal 1:

./loop-socat.sh

If this fails, you may need to install the socat package:

sudo apt install socat

Terminal 2:

sudo ./loop-slip-tap.sh

Then run QEMU as your normally would e.g.

make BOARD=qemu_x86 JS=samples/OcfServer.js qemu

Note: At this point, this setup is relatively unstable. You may experience crashes or things just not working in general. If the behavior does not seem normal you can usually fix it by restarting the two scripts and running QEMU again.

The original instructions document can be found on the Zephyr website here

Networking with BLE

It is possible to use IP networking over BLE using 6LowPAN. This is explained in a dedicated document.

Specific Device Support

ENC28J60 Ethernet Board

This SPI Ethernet board is now supported for use with the Arduino 101. To configure it, wire IO10-IO13 (the SPI pins) to CS, SI, SO, SCK on the board, respectively. Then wire VCC to 3.3V power (somewhere online I saw a reference that some of these boards tolerate 5V and some do not) and GND to ground. Finally, wire INT on the board to pin IO4; this is a GPIO used to communicate with the board as well.

Then when building a networking application, use FORCE=zjs_net_l2_enc28j60.json on your make command line to override the default Bluetooth/6LoWPAN networking.

For a simple test configuration, connect the Ethernet port to a secondary Ethernet on your host PC (I use a USB Ethernet device). Configure that interface on your PC with static IPv4 or IPv6 addresses that work with what's configured on the device. With the TCPEchoServ[46].js samples at present, you would use something like 192.168.201.2 w/ 255.255.255.0 mask for IPv4, and 2001:db8::2 w/ 64 prefix for IPv6.

(The simple board doesn't do auto-crossover detection so if your host Ethernet adapter doesn't either, you may need to use a crossover cable or hook them both up to a dedicated switch as I've done.)

Contributing

If you want to contribute code to the ZJS project, first you need to fork the project. The next step is to send a pull request (PR) for review to the ZJS repository. The PR will be reviewed by the project team members. You need at least two plus-ones (+1) , "Look Good To Me (LGTM)" or other positive signals for the project members. Once you have gained the required signals the project maintainers will merge the PR.

To report a security issue, please follow the procedure described here.

Travis and local sanity checking

We run a series of tests on each pull request and merged commit using Travis. This relies on a script in the repo called trlite. One easy way to run these tests on your local $ZJS_BASE git tree is to use make check or make quickcheck for a faster subset of the tests. These run with your code as it stands in your tree. This will not catch a problem like you failing to add a new file to your commit.

For a slightly safer sanity check, which might catch that kind of problem, you can run trlite directly or trlite linux for the "quick subset". This will clone a second copy of your git tree into a .trlite subdirectory, apply changes that git diff knows about, and run the build tests. Another option trlite -j will cause it to run four threads of tests to speed up execution; these will use four directories named .trlite[1-4]. If there is a test failure, the affected .trlite* trees are left in place so that you can investigate.

Repo Organization

File Descriptions

  • zjs-env.sh - Source this file to set environment variables and path to be able to use tools from scripts/ anywhere.
  • prj.conf - The main configuration file for a Zephyr application; overrides settings from a defconfig file in the Zephyr tree. In the ZJS builds, we assemble the prj.conf file at build time from other fragments.

Subdirectories

  • arc/ - Contains sensor subsystem code for ARC side of the Arduino 101.
  • cmake/ - Contains CMake build files for building Zephyr and JerryScript
  • deps/ - Contains dependency repos and scripts for working with them.
  • docs/ - Documentation in Markdown format (use API.md as index).
  • fragments/ - Contains project file fragments for project configuration.
  • modules/ - Contains different Javascript modules that can be loaded.
  • outdir/ - Directory generated by build, can be safely removed.
  • samples/ - Sample JavaScript files that can be built with make JS=.
  • scripts/ - Subdirectory containing tools useful during development.
  • src/ - JS API bindings for JerryScript written directly on top of Zephyr.
  • tests/ - JavaScript unit tests (incomplete).
  • tools/ - Helper utility for building JS using snapshot.

Zephyr is a trademark of the Linux Foundation. *Other names and brands may be claimed as the property of others.

zephyr.js's People

Contributors

brianjjones avatar cuiyanx avatar cwong1 avatar dbkinder avatar grgustaf avatar gvancuts avatar haoxli avatar ibelem avatar jausmus avatar jimmy-huang avatar johnvillalovos avatar kenchris avatar pfalcon avatar poussa avatar rdower avatar rwaldron avatar rzr avatar sergioamr avatar t-harvey avatar ttzeng avatar uhofemeier avatar xiaolongx avatar xiaoyu3x avatar zolkis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zephyr.js's Issues

[Buffer] length is not a readonly attribute

readonly attribute unsigned long length;

In buffer.md, the length of Buffer should be readonly, but actually it can be modified.

var buff = new Buffer(8);
var original = buff.length;
buff.length = buff.length + 1;
print(original);
print(buff.length);

The print result is 9, not the expected 8.

The RGB.js sample run fails

The RGB.js sample doesn't match the new promise-based gpio API.
We change the code:

var red = gpio.open({pin: pins.IO2, direction: 'out'});
to
var red = null;
gipo.open({pin: pins.IO2, direction: 'out'}).then(function(pin){
red = pin;
});

And the same change of the red, green and blue
Then move the setInterval() to the blue gpio.open statements. Then the test pass.

Rename "call_function" to be more clear

There's plenty to be confused about here. @kenchris indicated confusion about our "zjs_*_call_function" functions, whose purpose is to invoke a JS callback function at a later time, after serialization through a queue object. These functions know how to assemble the arguments for a particular JS callback.

Eventually we might have common argument patterns and reuse such functions, or even store the argument data in a declarative way so that one grand unified invoker/dispatcher function could call any JS callback appropriately.

But for now we will just try to rename them to be a little more clear about what they do. There are so many levels of callbacks here and such that there's no avoiding complexity. We could also stand to document the architecture of these callbacks somewhere to attempt to give an overview of the situtation. We drew it out on a whiteboard the other day and it was shockingly complex, but I think the complexity is all necessary.

make update should do git pull

I was expecting make update to do

  • git clone repo if it does not exists, or git pull to update to the HEAD from the origin
  • git check out the commit listed in deps/repos.txt

The git pull part missing. I ended up having an old git tree which did not have the commit id listed in repos.txt. So the tree is stuck with the cloned version.

Can we fix this?

Implement support for Arduino 101 accelerometer sensor

Node.js adaptation based on https://rawgit.com/w3c/accelerometer/gh-pages/index.html

**callback ListenerOrNull = any (...);**

interface Sensor : **EventEmitter** {
  readonly attribute SensorState state;
  readonly attribute SensorReading? reading;
  void start();
  void stop();
  **void on(String eventName, ListenerOrNull listener)**
  **// 'change' -> SensorReading **
  **// 'statechange' -> () **
  **// 'error' -> Error **
};

[Constructor(optional AccelerometerSensorOptions accelerometerSensorOptions)]
interface AccelerometerSensor : Sensor {
  readonly attribute AccelerometerSensorReading? reading;
  readonly attribute boolean includesGravity;
};

dictionary SensorOptions {
  double? frequency;
};

dictionary AccelerometerSensorOptions :  SensorOptions  {
  boolean includeGravity = true;
};

// throw TypeError when sensor cannot be constructed.

enum SensorState {
  "idle",
  "activating",
  "active",
  "errored"
};

[Constructor()]
interface SensorReading {
  **readonly attribute double timeStamp;**
  // Used to store a time value. The value could be a discrete point
  // in time or the difference in time between two discrete points in
  // time. The unit is milliseconds and should be accurate to 5 µs
  // (microseconds). However, if the browser is unable to provide a
  // time value accurate to 5 microseconds (due, for example, to
  // hardware or software constraints), the browser can represent the
  // value as a time in milliseconds accurate to a millisecond.
};

[Constructor(AccelerometerSensorReadingInit AccelerometerSensorReadingInit)]
interface AccelerometerSensorReading : SensorReading {
    readonly attribute double accelerationX;
    readonly attribute double accelerationY;
    readonly attribute double accelerationZ;
};

dictionary AccelerometerSensorReadingInit {
    double accelerationX = 0;
    double accelerationY = 0;
    double accelerationZ = 0;
};

Example:

var accelerometer = new AccelerometerSensor()
accelerometer.start();

accelerometer.on('change', function(reading) {
    console.log(reading.accelerationX);
});

accelerometer.on('error', function(error) {
    console.log(error.name, error.message);
});

make wo/ JS variable fails

Seems that the make system requires the JS variable. Otherwise, it fails always with:

zephyr.js/deps/zephyr/scripts/Makefile.build:45: zephyr.js/src/Makefile: No such file or directory

This is on a clean tree (new clone or git clean -dfx)

JS should be optional. In case it is missing, I think we should substitute it with empty string "".

Figure out how to support simple sensors like TMP36 with Generic Sensor API

The Generic Sensor API is based upon ideas from Johnny-Five, and Johnny-Five allows using the same API for simple sensors such as the TMP36.

We can do the same

var thermostat = new TemperatureSensor({ controller: "TMP36", pin: pins.A1 })
thermostat.start();

thermostat.on('change', function(reading) {
    console.log(reading.celsius);
});

thermostat.on('error', function(error) {
    console.log(error.name, error.message);
});

Question is how to do the implementation, as it is fully doable to do it in JavaScript directly.

Implement support for DHT22 temperature sensor

Based on generic sensor API with adaptation to Node.js and https://github.com/otcshare/thermometer/blob/gh-pages/index.html

**callback ListenerOrNull = any (...);**

interface Sensor : **EventEmitter** {
  readonly attribute SensorState state;
  readonly attribute SensorReading? reading;
  void start();
  void stop();
  **void on(String eventName, ListenerOrNull listener)**
  **// 'change' -> SensorReading **
  **// 'statechange' -> () **
  **// 'error' -> Error **
};

[Constructor(optional SensorOptions sensorOptions)]
interface TemperatureSensor : Sensor {
  readonly attribute TemperatureSensorReading? reading;
};

dictionary SensorOptions {
  double? frequency;
};

**dictionary TemperatureSensorOptions : SensorOptions {
  String? controller;
  unsigned short? pin;
}**

// throw TypeError when sensor cannot be constructed.

enum SensorState {
  "idle",
  "activating",
  "active",
  "errored"
};

[Constructor()]
interface SensorReading {
  **readonly attribute double timeStamp;**
  // Used to store a time value. The value could be a discrete point
  // in time or the difference in time between two discrete points in
  // time. The unit is milliseconds and should be accurate to 5 µs
  // (microseconds). However, if the browser is unable to provide a
  // time value accurate to 5 microseconds (due, for example, to
  // hardware or software constraints), the browser can represent the
  // value as a time in milliseconds accurate to a millisecond.
};

[Constructor(TemperatureSensorReadingInit temperatureSensorReadingInit)]
interface TemperatureSensorReading : SensorReading {
    readonly attribute unrestricted double? celsius;
    readonly attribute unrestricted double? fahrenheit;
    readonly attribute unrestricted double? kelvin;
};

dictionary TemperatureSensorReadingInit {
  unrestricted double? celsius;
  unrestricted double? fahrenheit;
  unrestricted double? kelvin;
};

Example:

var thermostat = new TemperatureSensor({ controller: "DHT", pin: pins.A1 })
thermostat.start();

thermostat.on('change', function(reading) {
    console.log(reading.celsius);
});

thermostat.on('error', function(error) {
    console.log(error.name, error.message);
});

K64F build is blocked by bug in Zephyr SDK 0.8.2

When you try to build for K64F now, you run into an error where gettimeofday() hasn't been declared. This is ZEP-644 in the Zephyr project. This issue is just to keep track of that one because it's blocking K64F development in Zephyr.js.

Compiling ARC is failing

~/repo/zephyr.js/arc (master)$ make
make[1]: Entering directory '/home/kenneth/repo/zephyr.js/deps/zephyr'
make[2]: Entering directory '/home/kenneth/repo/zephyr.js/arc/outdir'
  Using /home/kenneth/repo/zephyr.js/deps/zephyr as source for kernel
  GEN     ./Makefile
  CHK     include/generated/version.h
  CHK     misc/generated/configs.c
  CHK     include/generated/offsets.h
  CC      ../../arc/src/../../src/zjs_ipm.o
In file included from ../../arc/src/../../src/zjs_ipm.c:8:0:
../../arc/src/../../src/zjs_util.h:3:23: fatal error: jerry-api.h: No such file or directory
 #include "jerry-api.h"
                       ^
compilation terminated.
/home/kenneth/repo/zephyr.js/deps/zephyr/scripts/Makefile.build:182: recipe for target '../../arc/src/../../src/zjs_ipm.o' failed
make[3]: *** [../../arc/src/../../src/zjs_ipm.o] Error 1
/home/kenneth/repo/zephyr.js/deps/zephyr/Makefile:876: recipe for target '../../arc/src' failed
make[2]: *** [../../arc/src] Error 2
make[2]: Leaving directory '/home/kenneth/repo/zephyr.js/arc/outdir'
Makefile:173: recipe for target 'sub-make' failed
make[1]: *** [sub-make] Error 2
make[1]: Leaving directory '/home/kenneth/repo/zephyr.js/deps/zephyr'
/home/kenneth/repo/zephyr.js/deps/zephyr/Makefile.inc:73: recipe for target 'all' failed
make: *** [all] Error 2

Physical Web notification inconsistent with WebBluetoothDemo.js

This is unlikely to have anything to do with our code, since I can use scanner tools to see that we are advertising the Physical Web URL consistently AFAICT, but it seems indeterminate when a notification will show up on a client Android device.

One question for @kenchris, with the recent patch updating the short URL, have you seen a notification for this URL? Did you register this URL with Google Physical Web as I think you did the earlier one? When I tried to use my own custom URL I never once saw it show up as a notification, but when I switched back to your original one I started seeing it. So I concluded that Google will not actually display it unless you've registered it (on admittedly scant evidence).

Today I did find this page which describes how to enable Physical Web on your device. At the very bottom of the page it describes a known issue where Android can fail to display the notification. But its workaround steps don't seem to do me any good. I thought @poussa might be interested in this.

clearInterval fails if button press happens too quickly in Spaceship2.js

If you tap and release the pushbutton in this sample very quickly, you can get the message:native_clear_interval_handler: timer not found

If you do it enough times, you can get to where you have two ore more of the timer functions running at once and competing with each other for control of the LEDs.

Timer intervals stop after a short time with recent timer-update patch

@jprestwo, could you look into this?

With the latest commit c2787d, if I run ButtonLEDs.js, and I have a button wired up to IO4 and watch the lights flash and click the button 5-6 times, the interval events will stop arriving. If you don't give it any button input, it works indefinitely it seems.

In the previous commit, 3bafb0, it doesn't seem to have this problem.

ARC not compiling

Still having issues

arc (master)$ make BOARD=arduino_101_sss_factory
Using /home/kenneth/repo/zephyr.js/deps/zephyr/boards/arduino_101_sss/arduino_101_sss_factory_defconfig as base
Merging /home/kenneth/repo/zephyr.js/deps/zephyr/kernel/configs/nano.config
Merging prj.conf
#
# configuration written to .config
#
make[1]: Entering directory '/home/kenneth/repo/zephyr.js/deps/zephyr'
make[2]: Entering directory '/home/kenneth/repo/zephyr.js/arc/outdir'
  GEN     ./Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
  Using /home/kenneth/repo/zephyr.js/deps/zephyr as source for kernel
  GEN     ./Makefile
  CHK     include/generated/version.h
  CHK     misc/generated/configs.c
  UPD     misc/generated/configs.c
  CHK     include/generated/offsets.h
  CC      misc/generated/configs.o
  LD      misc/generated/built-in.o
  LD      misc/built-in.o
  CC      boards/arduino_101_sss/board.o
  LD      boards/arduino_101_sss/built-in.o
  LD      boards/built-in.o
  CC      src/../../src/zjs_ipm.o
/home/kenneth/repo/zephyr.js/arc/src/../../src/zjs_ipm.c:4:30: fatal error: ipm/ipm_quark_se.h: No such file or directory
 #include <ipm/ipm_quark_se.h>
                              ^
compilation terminated.
/home/kenneth/repo/zephyr.js/deps/zephyr/scripts/Makefile.build:182: recipe for target 'src/../../src/zjs_ipm.o' failed
make[3]: *** [src/../../src/zjs_ipm.o] Error 1
/home/kenneth/repo/zephyr.js/deps/zephyr/Makefile:884: recipe for target '/home/kenneth/repo/zephyr.js/arc/src' failed
make[2]: *** [/home/kenneth/repo/zephyr.js/arc/src] Error 2
make[2]: Leaving directory '/home/kenneth/repo/zephyr.js/arc/outdir'
Makefile:173: recipe for target 'sub-make' failed
make[1]: *** [sub-make] Error 2
make[1]: Leaving directory '/home/kenneth/repo/zephyr.js/deps/zephyr'
/home/kenneth/repo/zephyr.js/deps/zephyr/Makefile.inc:74: recipe for target 'all' failed
make: *** [all] Error 2

Grand Unified TODO List

We are tracking here the features and enhancements which should or will be implemented in the near future.

New APIs

  • CoAP
  • MQTT
  • W3C Sensors
  • File (Node.js)
  • HTTP (Node.js)
  • Console (Node.js)
  • Web USB (native)

Build

  • Update Zephyr and JerryScript to latest (now on 1.5 and 1.0)
  • Fix make clean to remove prj.conf and src/Makefile (PR #300)
  • Fix make clean to work even when tree is already clean (James)
  • Fix make to set ZEPHYR_BASE if not set
  • Add warning with helpful message if zephyr-env.sh hasn't been sourced
  • Add error with helpful message if zjs-env.sh hasn't been sourced (ZJS_BASE missing)
  • Check for nonexistent JS file rather than passing through to obscure minify error

Documentation

  • Add memory consumption numbers to wiki
  • Add matrix to indicate which APIs should work on each supported boards

API documentation

  • GPIO
  • AIO
  • PWM
  • BLE
  • A101 pins
  • K64F pins
  • Buffer

After pulling latest source + deps, jsrunner fails

make[3]: *** No rule to make target 'src/../../../deps/jerryscript/build/arduino_101_factory/librelease-cp_minimal.jerry-core.a', needed by 'src/built-in.o'.  Stop.
/home/kenneth/repo/zephyr.js/deps/zephyr/Makefile:884: recipe for target '/home/kenneth/repo/zephyr.js/src' failed
make[2]: *** [/home/kenneth/repo/zephyr.js/src] Error 2
make[2]: Leaving directory '/home/kenneth/repo/zephyr.js/build/outdir'
Makefile:173: recipe for target 'sub-make' failed
make[1]: *** [sub-make] Error 2
make[1]: Leaving directory '/home/kenneth/repo/zephyr.js/deps/zephyr'
/home/kenneth/repo/zephyr.js/deps/zephyr/Makefile.inc:74: recipe for target 'all' failed
make: *** [all] Error 2

@poussa @jimmy-huang

Should not returning false in JerryScript handlers for non-fatal errors

Currently we are returning false in all the JerryScript function handlers if there's error, but this would abort JerryScript engine and the program will just exit, iinstead, handle non-fatal errors more generously and set ret_val_p to an error or print a message instead of fatal abort, this needs to be examined in all of our code and it is case by case scenario.

make fails on clean tree

If you have a fresh clone or have done git clean -dfx, the make fails on first try.

$ make JS=samples/RGB.js

/home/spoussa/src/iot/zephyr/scripts/Makefile.clean:14: /home/spoussa/src/iot/zephyr.js/src/Makefile: No such file or directory

However, if you run the same command again, it works.

Support Generic Sensor APIs for common sensors

Some sensors are quite impossible to implement using I2C, GPIO etc on top of JS and that might also not be very efficient if it was possible.

For this Zephyr has the sensor subsystem: https://www.zephyrproject.org/doc/subsystems/sensor.html

This works with the very common DTH22 sensor for instance: https://www.adafruit.com/product/385

Sensors are relative easy to use in Zephyr (Might require to run on ARC, that is the only thing that I tested):

struct device *dev = device_get_binding("DHT");
while (1) {
        struct sensor_value temp, press, humidity;

        sensor_sample_fetch(dev);
        sensor_channel_get(dev, SENSOR_CHAN_TEMP, &temp);
        sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);

        SYS_LOG_INF("temp: %d.%06d; "
                "humidity: %d.%06d",
                temp.val1, temp.val2,
                humidity.val1, humidity.val2);

        task_sleep(sys_clock_ticks_per_sec/5);
    }
}

Unfortunately, a few changes might be required to Zephyr in order to set the pin from JS, as it is currently set by a build config CONFIG_DHT_GPIO_PIN_NUM

Here are a few of our W3C proposals for temperature and humidity sensors.

https://github.com/otcshare/thermometer/blob/gh-pages/index.html
https://github.com/otcshare/hygrometer/blob/gh-pages/index.html

These build upon: https://www.w3.org/TR/generic-sensor/#idl-index

(It is planned that the spec will align so that it will work on node.js, so I would say that it is fine replacing the EventTarget - ie onchange, onerror with an on("change") and on("error") event, at least until that gets settled)

Example code:

var sensor = new TemperatureSensor();
sensor.start();

sensor.onchange = function(event) {
    console.log(event.reading.celsius);
}

sensor.onerror = function(event) {
    console.log(event.error.name, event.error.message);
};

We could add the pin and sensor name as arguments to TemperatureSensor, ie

var sensor = new TemperatureSensor({ name: "DHT", pin: pins.A1 })

Building without specifying board (with 256) fails

Trying to not specify the board as Geoff told me to in another issue:

make[1]: Entering directory '/home/kenneth/repo/zephyr.js/deps/jerryscript'
/home/kenneth/repo/zephyr.js/deps/zephyr/Makefile.inc:35: *** Board arduino_101_factory_256 not found!.  Stop.
make[1]: Leaving directory '/home/kenneth/repo/zephyr.js/deps/jerryscript'
targets/zephyr/Makefile.zephyr:142: recipe for target 'build/arduino_101_factory_256/zephyr/zephyr.strip' failed
make: *** [build/arduino_101_factory_256/zephyr/zephyr.strip] Error 2

Implement support for Arduino 101 gyroscope sensor

Node.js adaptation based on https://rawgit.com/w3c/gyroscope/gh-pages/index.html

**callback ListenerOrNull = any (...);**

interface Sensor : **EventEmitter** {
  readonly attribute SensorState state;
  readonly attribute SensorReading? reading;
  void start();
  void stop();
  **void on(String eventName, ListenerOrNull listener)**
  **// 'change' -> SensorReading **
  **// 'statechange' -> () **
  **// 'error' -> Error **
};


[Constructor(optional SensorOptions sensorOptions)]
interface GyroscopeSensor : Sensor {
  readonly attribute GyroscopeSensorReading? reading;
};

dictionary SensorOptions {
  double? frequency;
};

// throw TypeError when sensor cannot be constructed.

enum SensorState {
  "idle",
  "activating",
  "active",
  "errored"
};

[Constructor()]
interface SensorReading {
  **readonly attribute double timeStamp;**
  // Used to store a time value. The value could be a discrete point
  // in time or the difference in time between two discrete points in
  // time. The unit is milliseconds and should be accurate to 5 µs
  // (microseconds). However, if the browser is unable to provide a
  // time value accurate to 5 microseconds (due, for example, to
  // hardware or software constraints), the browser can represent the
  // value as a time in milliseconds accurate to a millisecond.
};

[Constructor(GyroscopeSensorReadingInit GyroscopeSensorReadingInit)]
interface GyroscopeSensorReading : SensorReading {
    readonly attribute unrestricted double rotationRateX;
    readonly attribute unrestricted double rotationRateY;
    readonly attribute unrestricted double rotationRateZ;
};

dictionary GyroscopeSensorReadingInit {
    unrestricted double rotationRateX = 0;
    unrestricted double rotationRateY = 0;
    unrestricted double rotationRateZ = 0;
};

Example:

var gyroscope = new GyroscopeSensor()
gyroscope.start();

gyroscope.on('change', function(reading) {
    console.log(reading.rotationRateY);
});

gyroscope.on('error', function(error) {
    console.log(error.name, error.message);
});

Figure out exactly what's what on A101

We need to make sure we understand the external pin features of A101 more precisely. The comments on boards/arduino_101/pinmux.c seem to include everything we need to know, but we need to make sure we understand those things right.

For example, the AIO pins we've exposed so far are ain_9 - ain_14 there, aka AD5, AD0-AD4. But pins IO10-13 are also listed as ain_0 - ain_3... so does that mean they can also be analog inputs? Perhaps only from the ARC side? We need to set up some code to test out all these things and prove it to ourselves.

The AIO.js sample runs fail

We follow the steps:
make clean
make arc JS=samples/AIO.js
make dfu-arc (after reboot)
Except the information get from output:
ipm_console0: 'ARC---------------------------------------------'
ipm_console0: 'ARC - AIO processor from sensor core (ARC)!'
Nothing else.

Comments in samples seem wrong

ie in aio.js sample:

// Test code for Arduino 101 that uses the two onboard LEDs for output, and
// expects a button or similar input connected to digital pin 4.

print("Webbluetooth Demo with BLE...");

// import aio module
var aio = require("aio");

The BLE.js sample runs fail

We follow the steps:
make clean
make JS=samples/BLE.js
make dfu
The BLE.js runs fail and get the output:
Native_require_handler: module “ble” not found.
Jerryscript: canot run javascript
Develpers run this sample success. we will follow this issue and need your help to figure out the cause.

[WebBluetoothDemo.js] UI stops updating the temperature changes

After a while, maybe after 10 mins, the UI does not update the temperature changes any more. I see from the console that the changes are being recorded

Temperature change: 20.431640624999993 degrees Celsius

But the UI still show "24 C".

I also disconnected and reconnected but the issue remains. The LED control works fine.

Remove debug strings to save space

So far we've been adding descriptive strings left and right to help us debug, but we should disable the PRINT macro for "release" builds. Another idea is that we could report error numbers instead and map them to the appropriate string. We could pass an argument to PRINT with a unique ID number and then we'd be able to have an automated tool scan the source to collect the number-to-string mappings. The idea then would be some tool on the host side would be able to decode the error strings. Perhaps a script whose data source would get updated during each build.

convert.sh loses newlines

If an input JS file has a newline, convert.sh drops it; the result is that if there is a comment, the rest of the file will end up looking like it's commented out.

This could be fixed, but we might be better off going to my Python-based implementation from scripts/jsrunner. So we would pull the conversion routine out of there into a convert.py that replaces convert.sh, review it and make sure it covers at least everything that convert.sh does now.

This should be more cross-platform than bash scripts, and easier for any schmoe like me to read and understand - hence more maintainable. Another thought is we may need to deal with Unicode JS input at some point, and Python would be better suited to that.

Enable easy prototyping using remote node.js

One of the very nice features of Johnny-Five is that you can have a node.js instance running on your computer and then control your Arduino using that. That of course is not great for a shippable product :) but it is super nice for rapid development.

It would be interesting if we could enable something similar, by having something like a prototype flash image.

Improve pin mapping on Arduino101

pin mapping is a pain, especially since they don't correspond to what is written on the board and they differ between x86 and ARC core.

Johnny-five is known for providing mappings for common devices. We could do similarly like

var pins = require("arduino101_pinmux");

aio.open(... pin: pins.A0 )

@poussa

Implement support for DHT22 hygrometer sensor

Based on Generic Sensor API with Node.js adaptation and https://github.com/otcshare/hygrometer/blob/gh-pages/index.html

**callback ListenerOrNull = any (...);**

interface Sensor : **EventEmitter** {
  readonly attribute SensorState state;
  readonly attribute SensorReading? reading;
  void start();
  void stop();
  **void on(String eventName, ListenerOrNull listener)**
  **// 'change' -> SensorReading **
  **// 'statechange' -> () **
  **// 'error' -> Error **
};

[Constructor(optional SensorOptions sensorOptions)]
interface HumiditySensor : Sensor {
  readonly attribute HumiditySensorReading? reading;
};

dictionary SensorOptions {
  double? frequency;
};

**dictionary HumiditySensorOptions : SensorOptions {
  String? controller;
  unsigned short? pin;
}**

// throw TypeError when sensor cannot be constructed.

enum SensorState {
  "idle",
  "activating",
  "active",
  "errored"
};

[Constructor()]
interface SensorReading {
  **readonly attribute double timeStamp;**
  // Used to store a time value. The value could be a discrete point
  // in time or the difference in time between two discrete points in
  // time. The unit is milliseconds and should be accurate to 5 µs
  // (microseconds). However, if the browser is unable to provide a
  // time value accurate to 5 microseconds (due, for example, to
  // hardware or software constraints), the browser can represent the
  // value as a time in milliseconds accurate to a millisecond.
};

[Constructor(HumiditySensorReadingInit humiditySensorReadingInit)]
interface HumiditySensorReading : SensorReading {
    readonly attribute unrestricted double? relativeHumidity;
};

dictionary HumiditySensorReadingInit {
  unrestricted double? relativeHumidity;
};

Example:

var hygrometer = new HumiditySensor({ controller: "DHT", pin: pins.A1 })
hygrometer.start();

hygrometer.on('change', function(reading) {
    var t = themostat.celsius;
    var absoluteHumidity = 2.167 * reading.relativeHumidity * 6.112 * Math.exp(17.62 * t / 243.12 + t) / (273.15 + t);

    console.log("RH: " + reading.relativeHumidity);
    console.log("AH: " + absoluteHumidity);
});

hygrometer.on('error', function(error) {
    console.log(error.name, error.message);
});

convert.sh does not work on Mac

The below patch makes it work. Do we have a particular reason to use capital N ? Especially when we read one char at the time?

diff --git a/scripts/convert.sh b/scripts/convert.sh
index 9297a75..6020d9d 100755
--- a/scripts/convert.sh
+++ b/scripts/convert.sh
@@ -46,7 +46,7 @@ printf "const char script[] = \"" >> $OUTPUT
 # No field separator, read whole file (IFS=),
 # no backslash escape (-r),
 # read 1 character at a time (-n1)
-while IFS= read -r -N 1 char
+while IFS= read -r -n 1 char
 do
        if [ "$char" = "\"" ]; then
                printf "\\\\$char" >> $OUTPUT

SetInterval() would cause incoming BLE connection to fail midway

Currently there's an issue where if we add any setInterval() calls to the WebBluetoothDemo.js, the web client will not be able to connect to the device most of the time. It will get an error of Service Not Found. We theorize that this maybe that the fiber thread may not have returned the service id that was requested since the setInterval callbacks were taking up all the resources in the task thread. We might need to fix the main event loop to address this problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.