logo elektroda
logo elektroda
X
logo elektroda

OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST

p.kaczmarek2 12081 12

TL;DR

  • OpenBeken and Tasmota-compatible IoT devices can host a control page in LittleFS, using HTML, JavaScript, Ajax, and REST for live control without page reloads.
  • The page talks to /cm?cmnd= commands such as POWER, DIMMER, CT, and Ch1, so one generic SPA can control relays, dimmers, RGB, temperature, and channels.
  • A hello.html file stored in LittleFS becomes available at http://192.168.0.201/api/lfs/hello.html, and the examples run on a 12W LED lamp.
  • The demo buttons and sliders work on OpenBeken, and the same REST logic also works with Tasmota because the JSON and command format are compatible.
  • The main limitation is that the interface only works while the browser page stays open, so it is less suitable for persistent logging like BL0942 power graphs.
AI summary based on the discussion. May contain errors.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
📢 Listen (AI voice):
  • OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    I will show here how to create a website for any IoT device on multi-platform firmware OpenBeken , although the same approach will also offer compatibility with Tasmota (compatibility of sent commands and returned JSON format). We will write the device control page in HTML and Javascript, we will host it on the IoT device itself in the LittleFS file system, and the communication of this page with the device support itself will take place via Ajax and the REST interface, which means that the page will also refresh without reloading.

    The basis of the OpenBeken/Tasmota REST interface
    OpenBeken has a REST interface compatible with the Tasmota base, which means that the submission of commands and returned data is largely the same.
    We send the command itself via HTTP GET, for example:
    
    http://192.168.0.201/cm?cmnd=POWER%20ON
    

    It is a POWER command with an ON argument, i.e. switching on a relay or lighting a lamp.
    Then the device returns JSON:
    Code: JSON
    Log in, to see the code

    The commands and returned JSON are in the Tasmota documentation. It is also worth taking a look at the OBK documentation, which is constantly being developed.
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/README.md
    Information about the device can be retrieved by sending a command without an argument - eg POWER itself.

    Basic HTML, Javascript, JSON
    This topic assumes that the reader has a basic understanding of the topics mentioned in this paragraph. HTML (along with CSS) allows you to create the appearance of the page, its controls, and so on, Javascript allows you to properly script them - intercept events from the user and then send and receive data accordingly. Javascript here processes data in conjunction with Ajax, i.e. the page is not reloaded entirely, only Javascript itself sends data in the background, receives and updates only selected controls. JSON, on the other hand, is the format in which data is received, it allows for the textual representation of objects (with key/value pairs), arrays, etc.
    In this topic, I recommend, among others. W3 course:
    https://www.w3schools.com/html/
    https://www.w3schools.com/js/
    https://www.w3schools.com/js/js_ajax_intro.asp
    https://www.w3schools.com/js/js_json_intro.asp

    LittleFS file system on OpenBeken
    The LittleFS file system is available from the Web App panel, i.e. a panel that is itself downloaded from Github and communicates with the IoT device itself via the REST interface. Of course, it doesn't mean that you won't be able to access this panel without the Internet - if you want, you can host its sources in your network and simply change their address in the OBK configuration.
    We open the Web Panel:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    We open the LittleFS tab:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Here is the file system interface:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Create creates a new file, List refreshes their list.
    Here we can create autoexec.bat (which is executed at the beginning), any other scripts for the startScript command, and just HTML files and scripts.
    We can also drag existing files onto the field

    Hello World OBK
    We will create a basic document - Create File, hello.html:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    We can paste anything there - even a basic HTML document:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Code: HTML, XML
    Log in, to see the code

    This way (after saving) it will be available under the path:
    
    http://192.168.0.201/api/lfs/hello.html
    

    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Here is our first HTML document hosted (in this case) on a 12W LED lamp!

    REST interface - the simplest button
    OBK's REST interface is largely Tasmota compatible. All these POWER, STATUS commands are similarly implemented.
    So let's try to check the POWER (on/off) of the lamp.
    For ease of use, I've attached the bootstrap style here.
    For starters - ready example and result:
    Code: HTML, XML
    Log in, to see the code

    Code copy: https://github.com/openshwprojects/OpenBekenRESTDemo/blob/main/examples/Generic_Power.html
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    The above page is a SPA (Single Page Application), the simplest possible on OBK, demonstrating the use of Tasmota's POWER command to control the status of the LED.
    This page basically does two things:
    - after loading the window, it sends an empty POWER (no argument) to the device to retrieve the current LED power state
    - after clicking the button, it tries to switch the LED state to the opposite one
    The color of the button reflects the status of the LED:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    This excerpt:
    
    			let baseURL = "http://192.168.0.210";
    

    It allows me to run it on Windows, which is basically anywhere, because it sets the IP of the device. When uploading a device to LittleFS, this variable should be an empty string.
    The REST query after the HTTP GET executes this snippet:
    Code: Javascript
    Log in, to see the code

    According to Tasmota's documentation, POWER without an argument will only return the current state, and with an argument (ON, OFF or Toggle) it will change it.
    You can test this in a browser:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    This snippet refreshes the state of the LED when the page loads:
    Code: Javascript
    Log in, to see the code

    The following snippet is a helper function to change the color/style of the button:
    Code: Javascript
    Log in, to see the code

    And below we have the button itself - along with the API call with the TOGGLE argument (here with an additional space):
    Code: HTML, XML
    Log in, to see the code


    Brightness control bar
    Following this lead, we can add support for a dimmer. First you will need a slider:
    Code: HTML, XML
    Log in, to see the code

    Then you still have to somehow receive the initial state and handle its change.
    The change event is added like this:
    Code: Javascript
    Log in, to see the code

    There is no sendCmnd function yet, but sendPower is reworked to accept any command. This is because you can use the Dimmer command to control the brightness of the LED.
    Here is the whole code:
    https://github.com/openshwprojects/OpenBekenR...mo/blob/main/examples/LED_PowerAndDimmer.html
    Result:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Both the button and bar work. And even with Tasmota! Only then you have to save the HTML on the disk, and OBK has its own mini-hosting in LittleFS.


    Color change
    There is also a special HTML5 control for color selection:
    Code: HTML, XML
    Log in, to see the code

    It's just as easy to catch the event of its change:
    Code: Javascript
    Log in, to see the code

    In this case, I used the command from the OBK to make my work easier, led_basecolor_rgb returns the color in the form compatible with HTML.
    This is what the updated 'change' event looks like:
    Code: Javascript
    Log in, to see the code

    In addition, I modified the function sending the command so that it checks whether they exist before using the fields from the response:
    Code: Javascript
    Log in, to see the code

    Result:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Visually - the script is here:
    https://github.com/openshwprojects/OpenBekenR.../blob/main/examples/LED_PowerDimmerColor.html

    Light temperature
    The white temperature can be handled similarly. It is available in the CW and RGBCW products. Sometimes it is also emulated with RGB diodes (+ warm white diode), but about that another time.
    Just a command CT , which is also consistent with Tasmota.
    Here is the page after adding the second bar:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Added HTML:
    Code: HTML, XML
    Log in, to see the code

    Javascript (sending change):
    Code: Javascript
    Log in, to see the code

    Javascript (receiving the state, fragment to be pasted into the then block):
    Code: Javascript
    Log in, to see the code

    It is worth noting that thanks to the JSON structure of Tasmota, one block is enough to receive various values such as CT or POWER.
    Visually - the script is here:
    https://github.com/openshwprojects/OpenBekenR...examples/LED_PowerDimmerColorTemperature.html

    OpenBeken Channels

    OpenBeken introduces a slightly different concept from Tasmota, the so-called channels, which are really general purpose variables and allow you to chain different peripherals and scripts together. The channel can contain anything, from the state of the relay (1 or 0), through PWM (from 0 to 100), to e.g. a value read from the ADC or even just a simple event counter (e.g. if we want the system to take some action after N events action).
    Access to OpenBeken channels is available e.g. by the command:
    
    http://127.0.0.1/cm?cmnd=Ch1%20100
    

    Basic submission is Ch , then without spaces the channel index and . possibly its value if we want to set it and not just read it. Similar to Tasmota.
    Ch+4 style notation is also supported, where + means that we want to add something to the channel value.
    OBK then returns JSON like this:
    Code: JSON
    Log in, to see the code

    The presence of channels in a packet determines whether they are used - eg mapping a channel to a relay or ADC (or setting its type) causes the channel to appear in those used.
    Compatibility is also very important TuyaMCU . In OpenBeken, you can map any TuyaMCU variable to a channel, even one whose type was not provided during software development (for example, I don't know, pollen level in the air or gas concentration) and then pass it on for processing via the REST interface.
    In addition, there are slightly older commands that return a text value:
    - SetChannel [index] [value] - sets the channel to a given value and returns the current value
    - AddChannel [index] [value] - adds a value to the channel and returns the current value
    - GetChannel [index] - just returns the current value
    But in general it's better to use the common Ch* command I already mentioned.

    Based on duct access, I made a fryer controller just for fun:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    source on Github: https://github.com/openshwprojects/OpenBekenRESTDemo/blob/main/examples/TuyaMCU_AirFryer.html


    Downloading information about the device, sensors, electricity measurements
    OpenBeken also supports Tasmota-style STATUS commands, i.e. you can download a JSON description of the entire device status through them. For example, for a device with BL0942 (electricity measurement) we can obtain:
    Code: JSON
    Log in, to see the code

    Similarly for many other sensors, both in Tasmot and OpenBeken, eg the entire DHT family (DHT11 and similar), etc. also publishes its results in JSON.

    Can you go the other way?
    The entire presentation was based on the assumption that this IoT device is a mini server and responds to a GET request, but can it be done the other way around?
    It so happens that in OpenBeken there is a SendGET command, which also supports substituting variables (channels), so nothing stands in the way of reporting measurements from the device to an external server in the timer or in the onChange event (even one on HTTP hosting in the network). But about that another time.

    Summary
    The following conclusions can be drawn from this short game:
    - for both Tasmota and OpenBeken, you can easily write a simple page to control a given device
    - it can be hosted e.g. on OpenBeken itself in the LittleFS file system, but it can also be left as an HTML document on our computer, or on any HTTP hosting (e.g. on Raspberry)
    - such a page can have any style and any interface, you can do anything really with CSS
    - the REST interface basically gives access to everything, so it's possible to create really arbitrary controllers for any use
    - OpenBeken also offers a simple scripting language, so you can even place fields for creating automation on the website, e.g. you can configure the sprinkler switch-on time and then operate them on the OBK itself (firmware supports downloading time from NTP and supports events set for a given hour of a given day)
    The possibilities are really great. In addition to controlling a single device, you could basically also make one collective page for many devices, which is basically your own DIY Home Assistant.
    So are there any downsides?
    One of the downsides may be the nature of Javascript itself and the fact that such a site only works if we have it open in the browser, i.e. we will not, for example, record a nice record of power consumption measurements from BL0942 to the graph, unless we only want to have a time graph when we have a website open. By the way, I would like to add that information between sessions could be kept on the browser's side in cookies, but that's another thing...
    Still, I think the possibilities are still great. Soon I will try to present a more practical example of such a page, but that's for another topic.

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 14750 posts with rating 12866, helped 659 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • #2 20537714
    kassans
    Level 32  
    Posts: 1820
    Help: 130
    Rate: 412
    As always a great elaboration. I unfortunately encountered a problem with WB2S after winning your soft configuring wifi mqtt everything works until disconnected from the power supply for a few hours then to work I have to flash WB2S again then wifi appears and I can reconfigure.
  • ADVERTISEMENT
  • OpenBeken Tasmota JSON compatibility for energy data

    #3 20537738
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14750
    Help: 659
    Rate: 12866
    I'll be happy to try to help you, but start a separate topic. The description of the problem sounds strange to say the least. Disconnecting the power should not break anything, the data is stored in flash memory. In addition, reloading the software should not do anything to fix , because by uploading the batch you program only the offsets from 0x11000 to the end of the compiled firmware itself, and the device configuration is in memory a bit further. Simply reloading the software does not overwrite the configuration. So I don't know how uploading would help... well, unless you do erase all , i.e. you clear the entire 2MB of flash memory, then you also clear the configuration.

    Anyway - start a separate topic and we'll see.

    To make it a bit more on topic, I will add that OpenBeken compatibility with Tasmota's JSON format, e.g. with this:
    Code: JSON
    Log in, to see the code

    It also ensures compatibility with e.g. an application Tasmota Control with Google Play, as well as with ioBroker.

    I also used to add support for this JSON to a project on PIC:
    https://www.elektroda.pl/rtvforum/topic3789324.html
    Helpful post? Buy me a coffee.
  • Button link to LittleFS page via httpButtons

    #4 20626417
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14750
    Help: 659
    Rate: 12866
    UPDATE:
    If you want to make a button link to LittleFS on latest OBK version, do:
    
    startDriver httpButtons
    setButtonEnabled 0 1
    setButtonLabel 0 "Open Config"
    setButtonCommand 0 "*/api/lfs/cfg.html"
    setButtonColor 0 "#FF0000"
    

    The * marks that command is not OBK script command, but an URL and it will treated as such. Without *, it is treated as command to execute on OBK console:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    It will make a button on main page opening given link:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 20627012
    DeDaMrAz
    Level 23  
    Posts: 620
    Help: 34
    Rate: 130
    This is amazing!!! :D

    This is a whole new level of customization and configuration possibilities!!!

    Thank you!
  • #6 20627609
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14750
    Help: 659
    Rate: 12866
    Sample pages added to https://github.com/openshwprojects/OpenBekenRESTDemo/tree/main/examples , especially those two ones:
    
    TuyaMCU_RadarSensorConfig.html
    TuyaMCU_RadarSensorConfigAndResults.html
    
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • Tasmota fetch callback not firing on window.onload

    #7 20628668
    Jomsha
    Level 3  
    Posts: 11
    Rate: 2
    The "window.onload" function doesn't work with Tasmota.
    Only the "onclick" button event is working with Tasmota.
    They both are working with OpenBeken totally fine.

    I can't figure out why, the JSON Output is the same...

    Code: Javascript
    Log in, to see the code
  • OpenBeken and Tasmota REST API examples

    #8 20628688
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14750
    Help: 659
    Rate: 12866
    I have tried my best to keep my examples compatible with Tasmota, although OpenBeken features some more advanced API which is useful for handling TuyaMCU devices. @DeDaMrAz knows some more about it, as I have written an interface for his radar sensor. The code for his sensor will not work with Tasmota, as Tasmota doesn't even provide direct access to TuyaMCU dpIDs, as far as I know.

    The window.onload function is Javascript function, it doesn't have anything to do with Tasmota or OBK. You are most likely referring to REST API call that is done in window.onload.

    Regarding the sendPower code, best way to test it is to use web browser. First, without argument:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Then, with argument:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    To be clear, it's a Tasmota device:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    If it works with browser, then it must work in code, unless you have some kind of mistake in the script. The POWER sending sample I think is in the first post of this topic.

    Let me know if you need any REST javascript code examples for either OpenBeken or Tasmota. If you give me details, I can write a simple Javascript sample for you.
    Helpful post? Buy me a coffee.
  • Tasmota onload state not updating in Javascript

    #9 20628701
    Jomsha
    Level 3  
    Posts: 11
    Rate: 2
    p.kaczmarek2 wrote:
    I have tried my best to keep my examples compatible with Tasmota, although OpenBeken features some more advanced API which is useful for handling TuyaMCU devices. @DeDaMrAz knows some more about it, as I have written an interface for his radar sensor. The code for his sensor will not work with Tasmota, as Tasmota doesn't even provide direct access to TuyaMCU dpIDs, as far as I know.

    The window.onload function is Javascript function, it doesn't have anything to do with Tasmota or OBK. You are most likely referring to REST API call that is done in window.onload.

    Regarding the sendPower code, best way to test it is to use web browser. First, without argument:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    Then, with argument:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    To be clear, it's a Tasmota device:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    If it works with browser, then it must work in code, unless you have some kind of mistake in the script. The POWER sending sample I think is in the first post of this topic.

    Let me know if you need any REST javascript code examples for either OpenBeken or Tasmota. If you give me details, I can write a simple Javascript sample for you.


    Thanks , I already modified the code found on the git...
    This is my modified code:
    First is OpenBeken
    Second is Tasmota.
    "Onload" state of the Tasmota device doesn't get updated (2nd button stay blue) .
    user and pass are correct. tried even without user and pass. still no luck.
    I dont know what to do next.. tried everything

    Code: Javascript
    Log in, to see the code


    When I change the 2nd device to OpenBeken its all working fine.
  • Tasmota now enforces CORS on REST requests

    #10 20628733
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14750
    Help: 659
    Rate: 12866
    It looks like Tasmota has changed something recently. They are enforcing CORS policy now. I've found a related Reddit thread:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    You can see that in the connections of Chrome inspector:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    I've checked some Github threads for a SetOption setting for that, but I've found none so far. Of course it could be fixed with recompiling Tasmota, but it's not a perfect solution.

    I have tested it with latest Tasmota device and I can confirm there is a problem. I have currently fixed it by using Chrome extension:
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    OpenBeken as a mini HTTP hosting - writing pages in Javascript, Tasmota REST
    called "Moesif Origin & CORS Changer" but I don't like using Chrome extensions, they may be a vulnerability thread. I will try to find another solution if possible.
    Helpful post? Buy me a coffee.
  • #11 20628756
    Jomsha
    Level 3  
    Posts: 11
    Rate: 2
    Thanks for your testings.
    I Hope you'll find the best solution...
    I Don't know how to check those stuff...
  • #12 20628773
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14750
    Help: 659
    Rate: 12866
    Btw, if you want simple on/off access, why not try this approach?


    Helpful post? Buy me a coffee.
  • #13 20629078
    Jomsha
    Level 3  
    Posts: 11
    Rate: 2
    Actually I think I Will pass the option of HTML .
    I need to port forward all my devices to make it work for my purposes...

    Is anybody know a free cloud (mqtt) ?
    Tried hivemq but it can't connect...
📢 Listen (AI voice):

Topic summary

✨ The discussion focuses on utilizing OpenBeken firmware for mini HTTP hosting on IoT devices, allowing users to create web pages in HTML and JavaScript. The communication between the web page and the device is facilitated through Ajax and a REST interface, which is compatible with Tasmota. Users share experiences with device configurations, issues with Tasmota's CORS policy, and provide code snippets for creating buttons linked to the LittleFS file system. There are mentions of specific functionalities that work with OpenBeken but not with Tasmota, highlighting differences in API behavior. Additionally, users discuss challenges related to device power loss and configuration retention, as well as seeking alternatives for cloud MQTT services.
AI summary based on the discussion. May contain errors.

FAQ

TL;DR: 15 Q&A items, "mini server" approach: this FAQ helps IoT builders host OpenBeken HTML/JavaScript pages in LittleFS and control devices through Tasmota-style REST commands. It covers POWER, Dimmer, CT, STATUS JSON, channels, TuyaMCU mapping, CORS failures, and MQTT fallback decisions. [#20536282] Why it matters: A browser page can become a lightweight DIY Home Assistant-style controller without a separate server.

Option Hosting location REST compatibility Main limitation
OpenBeken LittleFS on device Tasmota-style commands plus OBK channels JavaScript runs only while the browser page is open
Tasmota External HTML file or hosting POWER, Dimmer, CT, STATUS patterns Recent firmware may enforce CORS on fetch()
Raspberry Pi or PC hosting LAN HTTP hosting or local disk Can call multiple devices by IP Needs network access to every target device

Key insight: OpenBeken turns the IoT device into both controller and HTTP host. Tasmota-style JSON keeps simple pages portable, but OBK channels and TuyaMCU access make deeper custom interfaces possible.

Quick Facts

  • OpenBeken serves LittleFS files under paths like /api/lfs/hello.html; the example used http://192.168.0.201/api/lfs/hello.html on a 12 W LED lamp. [#20536282]
  • The basic REST pattern is HTTP GET to /cm?cmnd=...; POWER ON returns JSON containing fields such as Dimmer, CT, POWER, and Channel. [#20536282]
  • STATUS JSON for a BL0942 device can report Voltage: 236, Current: 0.000, Power: 0, and energy totals in kWh-style values. [#20536282]
  • WB2S re-flashing normally programs from offset 0x11000; configuration sits further in flash and is only cleared by an erase-all operation of the 2 MB flash. [#20537738]
  • OpenBeken can add a main-page button to a LittleFS file with startDriver httpButtons, setButtonEnabled 0 1, and a URL command prefixed by *. [#20626417]

How do I host a custom HTML and JavaScript control page on an OpenBeken device using LittleFS?

Create an HTML file in the OpenBeken Web App LittleFS tab, then open it from /api/lfs/filename.html.
  1. Open the Web Panel and select LittleFS.
  2. Use Create File for hello.html or drag an existing file.
  3. Save it and browse to http://device-ip/api/lfs/hello.html.
The example served hello.html from 192.168.0.201 on a 12 W LED lamp. [#20536282]

What is LittleFS in OpenBeken and how is it used for mini HTTP hosting on IoT devices?

LittleFS stores HTML, scripts, and startup files directly on the OpenBeken device. "LittleFS is a device-side file system that stores web pages, scripts, and startup files, letting OpenBeken serve custom control interfaces over HTTP from the IoT device itself." The thread shows autoexec.bat, startScript files, and HTML pages in the same interface. Files become accessible through /api/lfs/, such as /api/lfs/hello.html. [#20536282]

How does the OpenBeken REST API work with Tasmota-compatible commands like POWER, Dimmer, CT, and STATUS?

OpenBeken accepts Tasmota-style HTTP GET commands through /cm?cmnd= and returns JSON. POWER ON switches a relay or lamp on. POWER without an argument reads current state. Dimmer 71 controls brightness, and CT controls white temperature. STATUS-style commands return structured JSON, including sensor and energy data. One example JSON contains Dimmer:71, CT:500, and POWER:"ON". [#20536282]

What is AJAX and why is it useful for controlling OpenBeken or Tasmota devices without reloading the web page?

AJAX lets JavaScript send REST requests and update selected controls without reloading the page. "AJAX is a browser communication method that sends background HTTP requests, receives responses such as JSON, and updates page elements without performing a full page reload." In the examples, fetch() calls /cm?cmnd=POWER and updates only the button color. The whole page remains loaded while the device state changes. [#20536282]

How can I create a simple JavaScript button that toggles a relay or LED using the Tasmota-style POWER command?

Create a button that calls fetch('/cm?cmnd=POWER TOGGLE') and updates its style from the returned JSON. The sample uses window.onload to send POWER first, so the page reads the initial state. The click handler sends POWER TOGGLE. If JSON returns POWER:"ON", the code sets the button to btn-success; otherwise it uses btn-danger. [#20536282]

How do I add brightness, color, and color temperature sliders to an OpenBeken web interface?

Add HTML controls and send OpenBeken or Tasmota-style commands on their change events. A brightness slider uses min="0" and max="100", then sends Dimmer value. A color picker sends led_basecolor_rgb with the HTML hex value minus #. A temperature slider sends CT value. The receiver updates controls when JSON includes Dimmer, led_basecolor_rgb, or CT. [#20536282]

OpenBeken vs Tasmota REST API — which is better for building custom browser-based IoT control pages?

OpenBeken is better when the page must live on the device or use channels; Tasmota is fine for basic compatible commands. Both support simple POWER, STATUS, Dimmer, and CT-style control. OpenBeken adds LittleFS mini-hosting and channel access. Tasmota can run the same HTML from disk or external hosting, but one forum test found recent Tasmota builds blocking some fetch() calls through CORS. [#20628733]

What are OpenBeken channels and how do Ch, SetChannel, AddChannel, and GetChannel commands work?

OpenBeken channels are general-purpose variables used for relays, PWM, ADC values, counters, and mapped peripherals. "OpenBeken channels are general-purpose firmware variables that store device states or readings, allowing relays, PWM outputs, ADC values, counters, scripts, and TuyaMCU data points to be connected through one REST-accessible model." Ch1 100 sets channel 1 to 100 and returns JSON such as Ch0 through Ch4. SetChannel, AddChannel, and GetChannel return text values, but Ch* is preferred. [#20536282]

How can TuyaMCU dpIDs be mapped to OpenBeken channels for custom devices like radar sensors or air fryers?

Map each TuyaMCU variable to an OpenBeken channel, then read or write that channel over REST. This works even when the original variable type was not known during firmware development. The thread gives examples such as air-quality values, gas concentration, an air-fryer controller, and radar sensor configuration pages. Two added files were TuyaMCU_RadarSensorConfig.html and TuyaMCU_RadarSensorConfigAndResults.html. [#20627609]

How do I read energy measurement data from BL0942 or other sensors using OpenBeken or Tasmota STATUS JSON?

Send a STATUS-style command and parse the returned StatusSNS JSON object. The BL0942 example returns ENERGY with Total, Yesterday, Today, Power, ApparentPower, ReactivePower, Factor, Voltage, and Current. The sample includes Voltage:236, Current:0.000, and Total:0.003. DHT-family sensors also publish readings as JSON in the same general style. [#20536282]

Why does a JavaScript window.onload fetch request work with OpenBeken but fail with recent Tasmota firmware?

The failure comes from the REST request inside window.onload, not from window.onload itself. A forum test found that recent Tasmota firmware enforced a CORS policy, so Chrome blocked the cross-origin fetch() response. OpenBeken answered the same JavaScript pattern normally. The visible symptom was a Tasmota button staying blue on load, while click handling still appeared to work in some tests. [#20628733]

How can I troubleshoot CORS errors when using fetch() from a custom HTML page to control Tasmota devices?

Test the exact /cm?cmnd=POWER URL in a browser, then inspect Chrome network errors for CORS blocking. If the URL works directly but fetch() fails, the issue is browser policy. One workaround used the Chrome extension "Moesif Origin & CORS Changer," but the author warned browser extensions may introduce security risk. A firmware rebuild could fix headers, but that was not presented as an ideal solution. [#20628733]

How do I add a button on the OpenBeken main page that opens a LittleFS-hosted configuration file like cfg.html?

Start the httpButtons driver and set a button command beginning with *. The * marks the command as a URL, not an OBK console command. Example commands enable button 0, label it Open Config, set command */api/lfs/cfg.html, and choose color #FF0000. Without the star, OpenBeken treats the text as a script command. [#20626417]

Why might a WB2S module running OpenBeken lose Wi-Fi or configuration after being disconnected from power for several hours?

Power loss should not erase OpenBeken configuration on WB2S because configuration is stored in flash memory. The author called the symptom strange and requested a separate diagnostic topic. Re-flashing normally writes from 0x11000 to the firmware end and does not overwrite configuration. Only an erase-all operation clears the full 2 MB flash, including configuration. [#20537738]

What free MQTT cloud broker can I use with OpenBeken or Tasmota if HiveMQ does not connect?

The thread does not identify a working free MQTT cloud broker. One user asked for a free cloud MQTT option after HiveMQ failed to connect, but no answer appears in the provided posts. The same user also noted that HTML control would require port forwarding all devices for their use case. Treat MQTT broker choice as unresolved in this thread. [#20629078]
AI summary based on the discussion. May contain errors.
ADVERTISEMENT