NEUTRON APPENGINE · QUICK START GUIDE
How to create, upload, test and debug an AppEngine application on Neutron
Create your first JavaScript application for Neutron, upload it to AppEngine and check measurements, logs and errors.
1. What we will build
We will create a JavaScript application that reads net, gross, tare and stability on Neutron and writes them to the device debug log. By default, it makes ten reading attempts, pausing one second between attempts, then stops. This makes startup, reading and completion easy to identify.
AppEngine runs the application on Neutron. The browser provides editing, upload and control. The app, scale and console objects belong to the Neutron runtime; do not run this example as a web page or a Node.js program.
For developers, IT teams, integrators and anyone building their own weighing application, including with AI assistance. Prepared by PRECIZ.
Neutron AppEngine – Quick Start Guide. Illustration introducing application development.
2. Prepare Neutron and the development environment
- Neutron with AppEngine API 1 and access to its management interface.
- The Neutron connection application and AppEngine editor, with permission to upload and run applications.
- An enabled weighing interface already displaying weight on Neutron. This example uses scale.read(); keep the built-in weighing interface enabled.
- Access to the Neutron debug output.
The JavaScript example does not change calibration, tare, zero, network or PIN-protected settings. It does not claim RS-232 or TCP. Disabling built-in interfaces applies to applications that claim communication ports themselves, such as the RAVAS–SAP example.
2.1 Open the application and connect Neutron over Bluetooth
Open the Neutron connection and application editor. It lets you write or open JavaScript, upload it and control execution.
- Enable Bluetooth on the computer and open the application in a browser supporting Web Bluetooth. Neutron must be powered on and reachable over BLE.
- Click Connect at the bottom. Select your Neutron in the browser device chooser and confirm.
- Wait for the green top strip to show Connected with and your device identifier. The bottom button becomes Disconnect. The screenshot shows an established connection.
- Click the orange </> icon in the top navigation to open AppEngine.
- Follow the numbered controls and upload/start procedure. Code visible in the editor is not necessarily installed or running.
Start with console.log("Hello World");, then open or paste the weight-reading application from this guide.
Before the first Run, set up the BLE diagnostic console in step 7 so you can see the output.
2.2 Identify the editor controls
AppEngine editor with numbered arrows. Button names match the application; explanations are in the table below.
The numbers in the image are explained in the table below. Enlarge the image to inspect the controls.
| 1 | Bluetooth connection | the green strip identifies the connected device. |
|---|---|---|
| 2 | AppEngine | the </> tab opens the JavaScript editor. |
| 3 | Open .js and editor | open a local file or type/paste code in the large dark area. |
| 4 | Name / Version | enter an application name and version, for example My application and 1.0.0. |
| 5 | Upload | sends the current editor contents to Neutron. Upload again after each code change. |
| 6 | Run / Stop | start or stop the installed application. Run does not execute editor changes that have not been uploaded. |
| 7 | Refresh status | updates application state. Expand Device details for busy and the last error. |
| 8 | Run automatically at device startup / Save attributes | enable automatic startup after testing and save the attributes. Save attributes does not replace Upload. |
| 9 | Debug console · BLE | displays device messages including console output. Clear clears the view, Auto-scroll follows new lines and Hide console hides it. |
No application installed means no application has been installed; Run and Stop can therefore be disabled. Open or enter code, fill Name/Version and Upload first.
Download .js saves the current editor contents to the computer. Search finds text and Expand enlarges the workspace. The global Save button at the bottom saves device settings; it does not upload application code.
3. Read one measurement first
Paste this standalone example into the editor. scale.read() returns the latest available snapshot synchronously; it does not request a new measurement or wait for stability.
const m = scale.read();
if (m.available && Number.isFinite(m.net)) {
console.info("MEASUREMENT", m.net, m.gross, m.tare, m.unit, m.stable);
} else {
console.warn("NO_MEASUREMENT", "status=" + m.status);
}The output contains net, gross, tare, unit and stability. stable=true means stable; stable=false means not yet stable. available=false means no valid measurement is available. scale.read() reference.
Without a timer, this example stays active after its initial output and waits for events. Press Stop before uploading the complete application.
4. Upload and run the application
- In the Neutron application, connect over BLE and open AppEngine with the </> icon. Stop any previous application. Use Refresh status and wait for busy: false before uploading.
- Use Open .js to open neutron-appengine-quick-start.js, or paste its entire source. Fill Name and Version.
- Click Upload. This installs the current code and checks syntax without executing user code; upload is not startup.
- After installation, click Run. Look for START followed by MEASUREMENT or NO_MEASUREMENT.
- Use Refresh status for state and the last error. Stop can end execution before the tenth reading attempt.
5. Configuration and execution flow
The complete application has two settings:
const config = {
intervalMs: 1000, // Premor po zakljucenem odcitku.
stopAfter: 10 // 0 pomeni neprekinjeno delovanje.
};intervalMs is a pause between reads of the latest snapshot, not the scale measurement rate. This example requires an integer of at least 250; the default 1000 ms keeps the log readable. stopAfter counts all attempts, including unavailable measurements; 0 runs continuously until Stop.
start() checks support → tick() reads and logs → setTimeout() schedules the next attempt → stop() finishes execution. The following methods belong to the same application; their variables and dependencies are defined in the complete source.
start() – check and start
Validates configuration and actual API 1, timer and scale support. Logs the interpreter and its version, then starts the first reading. Application version, interpreter version and API version are different values.
function start() {
if (!Number.isInteger(config.intervalMs) || config.intervalMs < 250) {
throw new Error("intervalMs must be an integer >= 250");
}
if (!Number.isInteger(config.stopAfter) || config.stopAfter < 0) {
throw new Error("stopAfter must be an integer >= 0");
}
const capabilities = app.capabilities();
if (capabilities.apiVersion !== 1 ||
!capabilities.features.timers || !capabilities.features.scale) {
throw new Error("AppEngine API 1, timers and scale are required");
}
console.info("START", capabilities.interpreter,
capabilities.interpreterVersion, "API=" + capabilities.apiVersion);
running = true;
tick();
}read() – one consistent snapshot
Returns one measurement object, so net, gross and tare belong to the same snapshot. The function is synchronous and needs no await.
function read() {
return scale.read();
}logMeasurement() – report the measurement
Checks availability and finite numeric values first. Valid snapshots log net, gross, tare, unit, stability and sequence. Status remains a diagnostic number; this example does not invent a status-code mapping.
function logMeasurement(measurement) {
count += 1;
if (!measurement.available ||
!Number.isFinite(measurement.net) ||
!Number.isFinite(measurement.gross) ||
!Number.isFinite(measurement.tare)) {
console.warn("NO_MEASUREMENT", "sample=" + count,
"status=" + measurement.status);
return;
}
console.info("MEASUREMENT", "sample=" + count,
"net=" + measurement.net, "gross=" + measurement.gross,
"tare=" + measurement.tare, "unit=" + measurement.unit,
"stable=" + measurement.stable,
"sequence=" + measurement.sequence);
}tick() – schedule the next reading
Schedules the next attempt after the current read finishes. At the attempt limit it calls stop() and returns immediately. Exceptions are handled within the same invocation.
function tick() {
timerId = null;
if (!running) return;
try {
logMeasurement(read());
if (config.stopAfter > 0 && count >= config.stopAfter) {
stop("sample limit");
return; // Po app.stop() ne nacrtujemo novega opravila.
}
// Naslednji odcitek nacrtujemo po koncu trenutnega.
timerId = setTimeout(tick, config.intervalMs);
} catch (error) {
reportError(error);
}
}stop() – finish cleanly
Cancels its timer and requests termination using app.stop(). This is not a Promise. Return or finish the function after calling it; do not schedule more work. AppEngine removes the context and timers on stop. There is no user shutdown callback.
function stop(reason) {
running = false;
if (timerId !== null) {
clearTimeout(timerId);
timerId = null;
}
console.info("STOP", reason, "samples=" + count);
app.stop();
}reportError() – a useful error message
Logs APP_ERROR, the code/name and message, then stops this example. console.error() alone does not stop an application; our stop() call does.
function reportError(error) {
console.error("APP_ERROR", error.code || error.name || "ERROR",
error.message || String(error));
stop("error");
}6. Test measurement, stopping and restarting
- Run the default application. Expect START and sample=1 through sample=10.
- Compare net, gross, tare and unit with the Neutron display; the unit need not be kg.
- Change the load and let it settle. Watch stable=false and stable=true. Infrequent reads may miss a brief unstable period.
- After the tenth attempt, expect STOP sample limit samples=10; confirm termination with Refresh status.
- Run again: the counter starts at 1 because every Run creates a new context.
- Set stopAfter to 0, stop, upload again and run. Check continuous operation and end it with Stop.
Illustrative line without the system prefix; the numbers are examples:
MEASUREMENT sample=1 net=10 gross=12.5 tare=2.5 unit=kg stable=true sequence=1237. Debugging: symptom, cause and correction
Find Debug console · BLE at the bottom of AppEngine (marker 9). In General, select Debug interface → bluetooth and Debug level → info for this example. Save device settings with the global Save button, return to AppEngine and Run.
console sends to the Neutron debug system, not browser developer tools. Messages have the prefix [JS:application name]. DI selects the output and DL the level; console.info() is INFO, visible with DL ≥ 3 on the selected output. Diagnostic reference.
- Syntax error on Upload: fix missing quotes/brackets, stop the previous run and upload again. Valid syntax does not prove all operations work.
- No START: click Run after Upload; use Refresh status for state/last error and check the debug output/level.
- NO_MEASUREMENT: Neutron must receive valid weight through an enabled weighing interface. Available and stable are different states.
- APP_ERROR: read the code/name and message, correct the cause, upload and rerun.
- BUSY: Stop, wait and confirm busy: false with Refresh status.
- RESOURCE_IN_USE in a communication extension: another system interface/application owns the port. This example claims no ports; follow the port-claim procedure for an RS-232/TCP application.
- Missing/truncated messages: console shares a limit of 10 calls/second and about 512 payload bytes/call. Keep messages short and increase the pause.
- TIMEOUT: read the reported phase/limit. Replace infinite loops and busy waiting with short timer-driven steps.
Exercise: introduce and fix an error
- In a copy of the complete application, set intervalMs: "abc".
- Stop, upload and run the copy. Syntax is valid, so the error appears on Run rather than necessarily on Upload.
- Expect APP_ERROR Error intervalMs must be an integer >= 250 and STOP error samples=0.
- Restore intervalMs: 1000, upload again and Run; expect START and readings.
For a second exercise, replace scale.read() inside read() with missingScale.read(). Expect APP_ERROR with ReferenceError; exact wording depends on the interpreter. Restore the correct call. Do not insert faults into an application already used in production.
8. Complete application and JavaScript download
Download the complete JavaScript application (.js)
The file contains the source below. Open it in AppEngine or paste the entire code. No additional libraries or npm packages are needed.
/* Neutron AppEngine API 1: quick start.
* Bere zadnji posnetek tehtnice in ga izpise v debug sistem naprave.
* Ne spreminja tare, nicle, nastavitev ali komunikacijskih vmesnikov.
*/
(function () {
"use strict";
const config = {
intervalMs: 1000, // Premor med odcitki, ne hitrost merjenja tehtnice.
stopAfter: 10 // 10 poskusov branja; 0 pomeni neprekinjeno delovanje.
};
let running = false;
let timerId = null;
let count = 0;
// En posnetek zagotovi medsebojno skladne neto, bruto in taro.
function read() {
return scale.read();
}
function logMeasurement(measurement) {
count += 1;
if (!measurement.available ||
!Number.isFinite(measurement.net) ||
!Number.isFinite(measurement.gross) ||
!Number.isFinite(measurement.tare)) {
console.warn("NO_MEASUREMENT", "sample=" + count,
"status=" + measurement.status);
return;
}
console.info("MEASUREMENT", "sample=" + count,
"net=" + measurement.net, "gross=" + measurement.gross,
"tare=" + measurement.tare, "unit=" + measurement.unit,
"stable=" + measurement.stable,
"sequence=" + measurement.sequence);
}
// app.stop() zahteva ustavitev; ni Promise in ni shutdown callbacka.
function stop(reason) {
running = false;
if (timerId !== null) {
clearTimeout(timerId);
timerId = null;
}
console.info("STOP", reason, "samples=" + count);
app.stop();
}
function reportError(error) {
console.error("APP_ERROR", error.code || error.name || "ERROR",
error.message || String(error));
stop("error");
}
function tick() {
timerId = null;
if (!running) return;
try {
logMeasurement(read());
if (config.stopAfter > 0 && count >= config.stopAfter) {
stop("sample limit");
return; // Po app.stop() ne nacrtujemo novega opravila.
}
// Naslednji odcitek nacrtujemo po koncu trenutnega.
timerId = setTimeout(tick, config.intervalMs);
} catch (error) {
reportError(error);
}
}
function start() {
if (!Number.isInteger(config.intervalMs) || config.intervalMs < 250) {
throw new Error("intervalMs must be an integer >= 250");
}
if (!Number.isInteger(config.stopAfter) || config.stopAfter < 0) {
throw new Error("stopAfter must be an integer >= 0");
}
const capabilities = app.capabilities();
if (capabilities.apiVersion !== 1 ||
!capabilities.features.timers || !capabilities.features.scale) {
throw new Error("AppEngine API 1, timers and scale are required");
}
console.info("START", capabilities.interpreter,
capabilities.interpreterVersion, "API=" + capabilities.apiVersion);
running = true;
tick();
}
try {
start();
} catch (error) {
reportError(error);
}
})();
9. Enable automatic startup after testing
After testing startup, readings, stopping and errors, enable Run automatically at device startup and click Save attributes. For continuous monitoring first set stopAfter: 0, upload and test that version. With the default 10, an automatically started application also stops after ten attempts.
At the next device startup, check START, readings and application state. Enabling automatic startup is not itself a functional test.
10. Continue with integration
AppEngine API reference describes the supported Neutron functions. Continue with RAVAS 3200–Neutron–SAP for an existing scale/business-system connection, or the Bluetooth BLE guide for browser communication.
When using AI, supply the API reference and request documented calls only. This example uses app.capabilities(), scale.read(), console, setTimeout(), clearTimeout() and app.stop(). Do not translate API identifiers.
Need help with your Neutron application?
Tell PRECIZ your scale model, required behaviour and target system. We help develop weighing applications and integrate devices.
Frequently asked questions
Does AppEngine run in the browser?
No. JavaScript runs on Neutron. The browser provides editing, Upload, Run, Stop and state checks. app and scale belong to the device runtime.
What is the difference between Upload and Run?
Open https://apps.scale-monitor.com/bleNeutron.html, connect over BLE and select AppEngine. Upload installs current editor contents; Run starts the installed application. Stop any previous run and confirm busy: false with Refresh status.
Where are console.info() and console.error() messages displayed?
In the Neutron debug system on the selected DI output at a suitable DL level, prefixed [JS:application name]. Browser developer tools are not the AppEngine runtime log.
Can I run the example without an available measurement?
If timer and scale APIs are supported, it logs NO_MEASUREMENT with status and counts attempts. Net, gross and tare require valid measurements. API support is different from measurement availability.
Does the counter survive a restart?
No. These variables belong to the current run. Each Run creates a new context and resets the counter. Persistent storage requires a separate implementation using the documented storage API.
How do I add TCP/IP, MQTT or WebSocket?
AppEngine provides documented communication APIs. Check capabilities, then implement the module, message format, connection and error handling. This starter reads measurements and logs; it does not start a TCP server or publish MQTT/WebSocket messages.
Need help?
Need help with software, connectivity or using a solution? Describe the issue so we can help with the next step.