Smart Home web page and dashboard
The house can serve a web page. It does this by itself once it is on your Wi-Fi, and a program can start its own page too. In code the page is home.dashboard.
The page the house serves by itself
Section titled “The page the house serves by itself”As soon as the house joins your Wi-Fi, it starts a web page on that network. You do not need a program for this. See Wi-Fi setup to get the house on Wi-Fi.
To open it, type the house’s address into a browser on a computer that is on the same Wi-Fi. The address is on the bottom line of the house’s screen, and home.wifi.ip() gives it too. For example:
http://192.168.1.20/The page that opens loads the MoBot Smart Home dashboard from ide.mobot.dz, so the computer needs internet. Until the dashboard appears, the page says Loading the dashboard from ide.mobot.dz....
The same page also gives plain readings. For example, http://192.168.1.20/sensors lists every reading at once, and /status says what the house can do. Open them in a browser to look. A browser’s address bar can only look. It cannot change anything.
The MoBot dashboard
Section titled “The MoBot dashboard”The dashboard is part of the MoBot IDE. It shows the house’s five modes, its sensors, its six outputs, Rules and History. You can open it in three ways:
- In any browser, by typing the house’s address, as above.
- In the web IDE, with View, then Dashboard. This opens a connect screen. Type the house’s address and the browser goes to the house’s own page.
- In the desktop MoBot, where the dashboard has its own window, under View, then Smart Home.
The buttons can change in later versions.
Start your own page from a program
Section titled “Start your own page from a program”home.dashboard.start() starts the house’s web page, and it gives back True when the page runs. There are two forms.
- On your Wi-Fi:
home.dashboard.start()with no arguments. If the house is already on Wi-Fi it is already serving, and the call just gives backTrue. If the house is not on Wi-Fi, the call gives backFalseand the screen saysWiFi not setandSetup: use app. - On its own network:
home.dashboard.start("MoBotHouse", "mobot1234"). The house makes its own Wi-Fi network with that name and password, and serves the page there. A phone or a laptop joins it like any other Wi-Fi. Choose a password of at least 8 characters. That is the usual rule for WPA2 Wi-Fi passwords, and the house’s own network uses WPA/WPA2 security. This stops the page the house was serving on your Wi-Fi, and the five modes that run inside it.
Give both the name and the password. If you give only one, you get a ValueError, unless you first called home.dashboard.set_ssid_password(ssid, password) to store them.
home.dashboard.ip() gives the address to type into a browser, or None when the page is not running. home.dashboard.is_running() says whether it runs, and home.dashboard.stop() stops it.
web = home.dashboard
ok = web.start("MoBotHouse", "mobot1234") # the house makes its own Wi-Fi networkif ok: print("Open http://" + str(web.ip())) fan_id = web.add_slider("/fan") # a control; the number says which one web.update_temperature(21) print(web.slider(fan_id))srv = mobotIOT.server
ok = srv.start_web_server("MoBotHouse", "mobot1234") # the house makes its own Wi-Fi networkif ok: print("Open http://" + str(srv.get_server_ip())) fan_id = srv.register_slider("/fan") # a control; the number says which one srv.update_temperature(21) print(srv.get_slider(fan_id))Add controls
Section titled “Add controls”A control is a switch, a slider, a colour picker or a text box that sits on your page. You give it a web address, such as "/light". The add call gives back a number. You use that number to read what someone sent.
| Add it with | Read it with | You get |
|---|---|---|
add_switch(path) |
switch(number) |
True when the switch is on. |
add_slider(path) |
slider(number) |
Where the slider is set. 0.0 until someone moves it. |
add_color(path) |
color(number) |
The picked colour, as {"r": ..., "g": ..., "b": ...}. |
add_text(path) |
text(number) |
The text that was typed. "" until someone types. |
On 2.x these were register_toggle, register_slider, register_rgb and register_text, and get_toggle, get_slider, get_rgb and get_text.
The dashboard in MoBot sends to these controls for you. The Web dashboard example also shows how to send to them by hand from a computer.
Show your own readings
Section titled “Show your own readings”Your program can put numbers on the page, with the update_ calls. Call them in a loop.
| Call | What it shows |
|---|---|
update_temperature(v) |
A temperature, in degrees Celsius. |
update_humidity(v) |
A humidity, in percent. |
update_gas(v) |
A gas reading, raw 0 to 4095. |
update_pot(v) |
The knob’s position, raw 0 to 4095. |
update_pir(v) |
True or False: whether the motion sensor sees something move. |
update_ldr(v) |
A light reading, raw 0 to 4095. |
When your program starts its own network, the page starts with fixed starting numbers, for example a temperature of 25.0, and not real readings. Until you call the update_ calls, those are what people see. The page the house serves by itself on your Wi-Fi shows real readings without any program. The update_ calls have the same names on 2.x.
Where next
Section titled “Where next”- Web dashboard example builds a page with a fan slider, a lamp switch, a colour picker and a message box.
- Dashboard reference lists every call.
- Smart Home lists every part of the house.