The PIC stores the values; the browser asks for the latest snapshot. Start with one fixed value, then add names and more readings.
Keep calling USB_NetworkService() from your main loop. It runs USB servicing, sets up the network address and handles browser requests. Your measurements and commands must leave time for it to run. Break slow work into short steps and avoid long delays.
Do
USB_NetworkService()
' Perform a short application step here.
Loop
Updating a value does not push it to the browser. Your code updates the stored values. The browser asks for /status, and the library replies with a snapshot in JSON format. The page chooses when to ask again. If your code changes a value ten times between requests, the page only sees the value in the next snapshot.
Browser mode owns TXReport and RXReport. Do not also call raw USB_Read(), USB_Write() or related packet functions to communicate with the page. Use the network value API instead.
|
State or counter |
Meaning |
|
The host has configured the USB device. This alone does not prove that networking is ready. |
|
|
USB_NetLink |
The host has enabled the RNDIS network link/packet filter. It does not mean a browser is open or a request has completed. |
|
USB_NetRequests |
HTTP requests handled by the device. |
|
USB_NetRxPackets, USB_NetTxPackets |
Received and transmitted network packet counters. They are not counts of application values. |
|
USB_NetDropped |
Count of dropped or malformed incoming network-transfer data. Useful when investigating communication problems. |
With Value capacity = 0, assign a number from 0 to 65535 to the library's Word variable:
USB_NetValue = 123
A request to /status returns {"value":123}. This simple option does not use the named-value setters.
For several readings, choose capacity 1–16, name each slot and set Values per response. For example, capacity 3 and names temperature, voltage, running create API indices 0, 1, 2. These calls publish three readings together:
USB_NetSetFixed(0, 2350, 2) ' temperature: 23.50
USB_NetSetFixed(1, 3300, 3) ' voltage: 3.300
USB_NetSetValue(2, 1) ' running: 1
USB_NetSetCount(3)
The JSON has the names directly at its top level:
{"temperature":23.50,"voltage":3.300,"running":1}
In JavaScript, read data.temperature, not data.values.temperature. JSON numbers do not preserve a display format after parsing: use data.temperature.toFixed(2) if the page should always display two decimal places.
|
Call |
Parameters and when to use it |
|
USB_NetSetValue(pIndex As Byte, pValue As SDword) |
Set zero-based slot pIndex to a signed integer from −2147483648 to 2147483647. Also restores integer formatting after a fixed-decimal or null value. |
|
USB_NetSetFixed(pIndex As Byte, pValue As SDword, pPlaces As Byte) |
Publish a scaled signed integer with 0–5 decimal places. For example, −12345 with 3 places means −12.345. No floating-point value is passed to this function. |
|
USB_NetSetNull(pIndex As Byte) |
Publish JSON null when no valid reading is available. The page should display an explanation or dash, rather than treat it as zero. |
|
USB_NetSetCount(pCount As Byte) |
Include the first pCount named slots in subsequent snapshots. Allowed range is 0 through capacity. Count 0 returns {}. |
These procedures set USB_Result: USB_OK on success, USB_BAD_LENGTH for an invalid index/count/decimal-place argument, or USB_NOT_SUPPORTED when named output is not enabled. Check the result immediately when arguments are variable; another API call can replace it.
Capacity is the number of slots reserved when you compile. Count is how many of the first slots appear in the next response; your program can change it. A smaller count does not free RAM. Count 2 always selects slots 0 and 1. To show four fields when one reading is unavailable, keep count at 4 and set that field to null.
Set related values consecutively before the next USB_NetworkService() call. The resulting request snapshot stays consistent while it is transmitted. Prefer these setters to writing USB_NetValues[] directly, because the setters also manage integer, decimal and null formatting. USB_NetCount holds the active count; use USB_NetSetCount() to validate a change.
Created with the Personal Edition of HelpNDoc: Generate EPub eBooks with ease