### Install Development Dependencies Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Install the required multilib compiler packages on Debian-based systems. ```bash $ sudo apt-get install gcc-multilib g++-multilib ``` -------------------------------- ### Start Local Web Server Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Run a local web server to serve project files. ```bash $ sudo python3 -m http.server 80 ``` ```bash $ sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000 $ python3 -m http.server ``` -------------------------------- ### GET /setup Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Configures device settings including location, language, timezone, and wake/sleep schedule. ```APIDOC ## GET /setup ### Description Configures device settings including location, language, timezone, and wake/sleep schedule. ### Method GET ### Endpoint /setup ### Parameters #### Query Parameters - **j** (float) - Optional - Latitude (for weather) - **k** (float) - Optional - Longitude (for weather) - **l** (string) - Optional - Language (uk, it, fr, es, de) - **c** (string) - Optional - City code (timezone) - **d** (integer) - Optional - Daylight Saving Time (0 or 1) - **w** (integer) - Optional - Wake up hour (0-23) - **b** (integer) - Optional - Bedtime hour (0-23) - **t** (integer) - Optional - Tai Chi frequency (0=off, 40=high, 80=medium, 255=low) ``` -------------------------------- ### GET /say Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Uses text-to-speech to make the device speak. ```APIDOC ## GET /say ### Description Uses Google Translate TTS to speak the provided text. ### Method GET ### Endpoint /say ### Parameters #### Query Parameters - **t** (string) - Required - Text to be spoken ``` -------------------------------- ### GET /play Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Plays audio files from a URL or uses text-to-speech. ```APIDOC ## GET /play ### Description Plays sounds or MP3 files from URLs. Note: HTTPS URLs are not supported. ### Method GET ### Endpoint /play ### Parameters #### Query Parameters - **u** (string) - Required - URL of the audio file to play ``` -------------------------------- ### List and String Operations Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for working with lists and strings, including getting heads, checking for nil, and hashing. ```APIDOC ## List and String Operations ### HD **Description**: Get the head of a list. **Parameters**: ( list -- list x ) ### NIL **Description**: Push an empty list onto the stack. **Parameters**: ( -- list ) ### MD5 **Description**: Compute the MD5 hash of a string. **Parameters**: ( str -- hash ) ``` -------------------------------- ### Forth: Task Management Words Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Create and manage background tasks. Tasks can be started with a code string, delay, and name. They can be stopped, suspended, and resumed by their ID. ```forth \ List all tasks .tasks ``` ```forth \ Start a new periodic task (code delay-ms name) "my-task-code" 5000 "my-task" start-task \ Returns: task-id ``` ```forth \ Stop a task by ID 1 stop-task ``` ```forth \ Suspend a task 1 suspend-task ``` ```forth \ Resume a suspended task 1 resume-task ``` -------------------------------- ### Get Device Status Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Retrieves the current device status including network, ear, LED, and configuration information as a JSON object. ```bash # Get comprehensive device status curl http://192.168.1.100/status ``` -------------------------------- ### GET /update-weather Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Triggers an update of the weather information. ```APIDOC ## GET /update-weather ### Description Triggers an update of the weather information. ### Method GET ### Endpoint /update-weather ``` -------------------------------- ### Forth: Stack and Memory Operations Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Standard Forth stack manipulation and memory operations. Includes examples for duplicating, swapping, rotating, dropping, and copying stack items. Variable and constant definitions are also shown. ```forth \ Stack operations 5 dup . . \ Output: 5 5 ``` ```forth 1 2 swap . . \ Output: 1 2 ``` ```forth 1 2 3 rot . . . \ Output: 1 3 2 ``` ```forth 1 2 drop . \ Output: 1 ``` ```forth 1 2 over . . . \ Output: 1 2 1 ``` ```forth \ Variables variable my-var 42 my-var ! \ Store 42 in my-var my-var @ . \ Output: 42 ``` ```forth \ Constants 100 constant my-const my-const . \ Output: 100 ``` ```forth \ Arithmetic 10 5 + . \ Output: 15 ``` ```forth 10 5 - . \ Output: 5 ``` ```forth 10 5 * . \ Output: 50 ``` ```forth 10 5 / . \ Output: 2 ``` -------------------------------- ### GET /status Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Retrieves the current status of the Nabaztag device, including network information, ear positions, LED states, and configuration. ```APIDOC ## GET /status ### Description Returns the current status of the Nabaztag including network info, ear positions, LED states, time, and configuration as a JSON object. ### Method GET ### Endpoint /status ### Response #### Success Response (200) - **status** (object) - JSON object containing device state, network info, and hardware configuration. ``` -------------------------------- ### GET /update-time Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Triggers an update of the device time from an NTP server. ```APIDOC ## GET /update-time ### Description Triggers an update of the device time from an NTP server. ### Method GET ### Endpoint /update-time ``` -------------------------------- ### Forth: HTTP Request Words Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Perform HTTP GET and POST requests from Forth. 'http-get' returns content and headers. 'http-post' sends data. JSON parsing and field access are supported. ```forth \ HTTP GET request "http://example.com/api/data" http-get \ Stack: content header ``` ```forth \ HTTP POST request "param=value" "http://example.com/api/endpoint" http-post \ Stack: content header ``` ```forth \ Parse JSON response "http://api.example.com/data.json" http-get drop json-parse \ Stack: parsed-json-object ``` ```forth \ Access JSON fields "daily.weathercode[0]" json-get . ``` -------------------------------- ### Build Compiler and Simulator Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Compile the project's compiler and simulator components. ```makefile $ make compiler ``` -------------------------------- ### Build Firmware Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Compile the firmware for the Nabaztag device. ```makefile $ make firmware ``` -------------------------------- ### Configure Nabaztag Device Settings Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Use curl to send configuration parameters to the device. Ensure correct values for latitude, longitude, language, timezone, DST, wake/sleep hours, and Tai Chi frequency. ```bash # Full configuration example curl "http://192.168.1.100/setup?j=45.4642&k=9.1900&l=uk&c=Europe/London&d=1&w=8&b=22&t=80" ``` ```bash # Update time from NTP server curl http://192.168.1.100/update-time ``` ```bash # Update weather information curl http://192.168.1.100/update-weather ``` -------------------------------- ### Home Automation Integration Placeholder (Python) Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt A placeholder Python script for integrating with home automation systems. This snippet is intended to be expanded with specific automation logic. ```python #!/usr/bin/python ``` -------------------------------- ### System and Time API Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for retrieving system time, uptime, and network information. ```APIDOC ## TIME&DATE ### Description Push the current time and date onto the stack. ### Response - **sec, min, hour, day, month, year** (numbers) - Current date and time components ## UPTIME ### Description Push the system uptime in seconds onto the stack. ### Response - **s** (number) - Uptime in seconds ## UPDATE-WEATHER ### Description Update weather and air quality information from the network. ``` -------------------------------- ### POST /forth Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Executes Forth code on the device and returns the output and stack state as JSON. ```APIDOC ## POST /forth ### Description Executes Forth code on the device and returns the output and stack state as JSON. ### Method POST ### Endpoint /forth ### Parameters #### Request Body - **c** (string) - Required - The Forth code string to execute ### Response #### Success Response (200) - **output** (string) - The output generated by the Forth code - **stack** (string) - The final state of the stack ``` -------------------------------- ### Nabaztag Server Configuration Parameters Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt This section lists and describes the various configuration parameters available for the Nabaztag server. These parameters control different aspects of the device's behavior, from information display to network settings. ```APIDOC ## Nabaztag Server Configuration Parameters ### Description This document details the configuration parameters for the Nabaztag server, covering various settings for information display, device control, and user preferences. ### Parameters #### Info Parameters - **INFO-PALETTE** (string) - Info LED palette (16 cells) - **INFO-POLLUTION** (string) - Info pollution - **INFO-SERVICE4** (string) - Info service 4 - **INFO-SERVICE5** (string) - Info service 5 - **INFO-STOCK** (string) - Info stock - **INFO-TRAFFIC** (string) - Info traffic - **INFO-WEATHER** (string) - Info weather #### General Settings - **LANGUAGE** (string) - Language - **LATITUDE** (float) - Latitude (weather/air quality) - **LONGITUDE** (float) - Longitude (weather/air quality) - **SERVER-URL** (string) - Server URL - **WEATHER-CODE** (string) - Weather code #### LED Control - **LED-BASE** (string) - Base LED color override - **LED-BASE-BREATHING** (string) - Base LED breathing effect - **LED-CENTER** (string) - Center LED color override - **LED-LEFT** (string) - Left LED color override - **LED-NOSE** (string) - Nose LED color override - **LED-RIGHT** (string) - Right LED color override #### User and Security - **MD5-PASSWORD** (string) - Login password (MD5 hashed) - **USERNAME** (string) - Login username #### Scheduling and Timing - **SURPRISE-NEXT-TIME** (string) - Next surprise time - **TAICHI-FREQ** (string) - Tai Chi frequency - **TAICHI-NEXT-TIME** (string) - Next taichi time - **WAKE-UP-AT** (string) - Wake up at (hour) #### Network Settings - **NTP-SERVER** (string) - NTP server ``` -------------------------------- ### Memory and System Management Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands related to memory management, garbage collection, and system utilities. ```APIDOC ## Memory and System Management ### FREE-CELL **Description**: Free a cell in memory at the given address. **Parameters**: ( addr -- ) ### GC **Description**: Perform garbage collection and return the memory usage percentage. **Parameters**: ( -- mem% ) ### INTERPRETER **Description**: Interactive Forth interpreter. **Parameters**: ( -- ) ### PROMPT **Description**: Display the Forth interpreter prompt. **Parameters**: ( -- ) ``` -------------------------------- ### POST /leds Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Sets LED color overrides for the nose, left, center, right, and base LEDs. ```APIDOC ## POST /leds ### Description Sets LED color overrides for nose, left, center, right, and base LEDs. Colors are hex values (#rrggbb) or -1 to disable override. ### Method POST ### Endpoint /leds ### Parameters #### Request Body - **n** (string) - Optional - Nose LED color hex or -1 - **l** (string) - Optional - Left LED color hex or -1 - **c** (string) - Optional - Center LED color hex or -1 - **r** (string) - Optional - Right LED color hex or -1 - **b** (string) - Optional - Base LED color hex or -1 ``` -------------------------------- ### Utility Commands Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt General utility commands. ```APIDOC ## Utility Commands ### HELP **Description**: Display help information. **Parameters**: ( -- ) ### LOGIN **Description**: Login command. **Parameters**: ( -- ) ### MS **Description**: Sleep for the specified number of milliseconds. **Parameters**: ( delay -- ) ### METEO>INFO **Description**: Convert weather code to info code. **Parameters**: ( n -- n ) ``` -------------------------------- ### Forth: Wake Up Rabbit Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Command to wake up the Nabaztag. ```forth \ Wake up the rabbit wake-up ``` -------------------------------- ### Control LEDs Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Sets color overrides for specific LEDs using hex values or -1 to disable the override. ```bash # Set left LED to red, center to green, disable others curl -X POST "http://192.168.1.100/leds" \ -d "n=-1&l=%23ff0000&c=%2300ff00&r=-1&b=-1" # Turn nose LED red curl -X POST "http://192.168.1.100/leds" \ -d "n=%23ff0000" # Clear all LED overrides (return to automatic mode) curl -X POST "http://192.168.1.100/leds" \ -d "n=-1&l=-1&c=-1&r=-1&b=-1" ``` -------------------------------- ### Device Control API Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for controlling the physical state and audio of the Nabaztag. ```APIDOC ## SAY ### Description Performs text-to-speech output. ### Parameters - **text** (string) - Required - The text to be spoken ## SLEEP ### Description Put the Nabaztag into sleep mode. ## WAKE-UP ### Description Wake up the Nabaztag from sleep mode. ## VOLUME ### Description Get the current audio volume. ### Response - **vol** (number) - The current volume level ``` -------------------------------- ### Trigger Actions Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Executes predefined device actions such as animations, system stops, or reboots. ```bash # Do Tai Chi exercise (choreographed ear and LED movements) curl http://192.168.1.100/taichi # Trigger surprise action (random sound and animation) curl http://192.168.1.100/surprise # Stop all current movements and sounds curl http://192.168.1.100/stop # Reboot the device curl http://192.168.1.100/reboot ``` -------------------------------- ### Device Control and Information Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for controlling device features like ears, playing sounds, and loading data. ```APIDOC ## Device Control and Information ### GET-HOUR **Description**: Get the current hour. **Parameters**: ( -- hour ) ### GET-MINUTE **Description**: Get the current minute. **Parameters**: ( -- minute ) ### LOAD-INFO-ANIMATION **Description**: Load info animation from the server. **Parameters**: ( filename anim_num -- ) ### LOAD-INFO-ANIMATIONS **Description**: Load info animations from the server. **Parameters**: ( -- ) ### LOAD-SRV **Description**: Load a Forth file from the server. **Parameters**: ( filename -- ) ### MOVE-EAR **Description**: Move an ear in a specified direction to a position. (0=left, 1=right) for ear, (0=left, 1=right) for direction, (0..16) for position. **Parameters**: ( ear dir pos -- ) ### PLAY-CHOR **Description**: Play a choreography. **Parameters**: ( chor_data -- ) ### PLAY-MIDI **Description**: Play a MIDI sound/note. If i>=100, play note. If 0<=i<100, play sound i. If i<0, play a random note. **Parameters**: ( i -- ) ### PLAY-URL **Description**: Play a WAV file from an HTTP URL. HTTPS is not supported. **Parameters**: ( url -- ) ``` -------------------------------- ### Forth: Audio Playback Words Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Control audio playback including MIDI notes, URLs, and text-to-speech. Built-in sounds are 0-99, notes are 100+. Use 'play-url' for HTTP audio. ```forth \ Play a MIDI sound (0-99 = built-in sounds) 50 play-midi ``` ```forth \ Play a MIDI note (100+ = note number, middle C = 160) 160 play-midi ``` ```forth \ Play random note -1 play-midi ``` ```forth \ Play audio from URL (HTTP only) "http://example.com/sound.mp3" play-url ``` ```forth \ Text to speech "Hello World" say ``` ```forth \ Play a choreography from server "http://server/config/chor/taichi.chor" http-get drop play-chor ``` -------------------------------- ### Forth: Play MIDI Note Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Play a MIDI note on the Nabaztag. The number represents the MIDI note value (e.g., 60 for middle C). ```forth \ Play a MIDI note (middle C) 60 play-midi ``` -------------------------------- ### Set Service Status Indicators Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Configures the nose LED blinking patterns to represent various service statuses. ```bash # Set nose LED to indicate 2 pending messages (0=off, 1-4=blink patterns) curl "http://192.168.1.100/nose?v=2" # Set weather display (0=sun, 1=clouds, 2=fog, 3=rain, 4=snow, 5=storm) curl "http://192.168.1.100/weather?v=3" # Set stock market indicator (0-6 scale) curl "http://192.168.1.100/stock?v=4" # Set mail status (0-3 scale) curl "http://192.168.1.100/mail?v=1" # Set pollution level (0-10 scale based on European Air Quality Index) curl "http://192.168.1.100/pollution?v=5" # Clear all service indicators curl http://192.168.1.100/clear ``` -------------------------------- ### Event Hooks Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands that define hooks for various device events. ```APIDOC ## Event Hooks ### ON-CLICK **Description**: Click hook. **Parameters**: ( -- ) ### ON-CONNECT **Description**: Connection hook. **Parameters**: ( -- ) ### ON-DBL-CLICK **Description**: Double click hook. **Parameters**: ( -- ) ### ON-EARS **Description**: Ears hook. **Parameters**: ( -- ) ### ON-HALFTIME **Description**: Half-hour hook. **Parameters**: ( -- ) ### ON-RFID **Description**: RFID hook. **Parameters**: ( rfid -- ) ### ON-TIME **Description**: Hour hook. **Parameters**: ( -- ) ``` -------------------------------- ### Input/Output and Data Manipulation Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for emitting characters, evaluating strings, and manipulating data on the stack. ```APIDOC ## Input/Output and Data Manipulation ### EMIT **Description**: Emit character. **Parameters**: ( char -- ) ### EVAL-TRAME **Description**: Evaluate a trame. **Parameters**: ( str -- ) ### EVALUATE **Description**: Evaluate a string as Forth code. **Parameters**: ( str -- ) ### JSON-GET **Description**: Get an element from a dictionary or list by path (e.g., "daily.weathercode[0]"). **Parameters**: ( w path -- x ) ### JSON-PARSE **Description**: Parse a JSON string into a list or dictionary. **Parameters**: ( str -- list/dict ) ### LOCAL>STRING **Description**: Push the current local time and date as a string onto the stack. **Parameters**: ( -- str ) ### LOWER **Description**: Convert string s to lowercase. **Parameters**: ( s -- s ) ### NTH **Description**: Get the n-th element of a list or the n-th character of a string. **Parameters**: ( list/str n -- x ) ### PAD_LEFT **Description**: Pad string s on the left to length n with character c. **Parameters**: ( s n c -- s ) ### PAD_RIGHT **Description**: Pad string s on the right to length n with character c. **Parameters**: ( s n c -- s ) ### NIP **Description**: Drop the first item below the top of stack. **Parameters**: ( n1 n2 -- n2 ) ### OVER **Description**: Make a copy of the second item on top of the stack. **Parameters**: ( n1 n2 -- n1 n2 n1 ) ``` -------------------------------- ### Execute Forth Code via HTTP POST Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Send Forth commands to the device using a POST request to the /forth endpoint. The 'c' parameter contains the Forth code. Responses include output and stack state. ```bash # Execute simple Forth commands curl -X POST "http://192.168.1.100/forth" \ -d "c=left-ear%20forward%2010%20move-ear" ``` ```bash # Get current ear positions curl -X POST "http://192.168.1.100/forth" -d "c=ears" # Response: { "output": "", "stack": "0 0" } ``` ```bash # Play a MIDI note (middle C = 60 + 100 offset) curl -X POST "http://192.168.1.100/forth" -d "c=160%20play-midi" ``` ```bash # Get current time curl -X POST "http://192.168.1.100/forth" -d "c=daytime" # Response: { "output": "14:30:45 UTC\n", "stack": "" } ``` ```bash # Multi-command example: wake up and play sound curl -X POST "http://192.168.1.100/forth" \ -d "c=wake-up%20%22Hello%22%20say" ``` -------------------------------- ### Forth: Time and Weather Words Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Access current time and weather information. 'daytime' displays UTC time. 'time&date' pushes components to the stack. 'update-weather' fetches new data. ```forth \ Display current time (UTC) daytime \ Output: 14:30:45 UTC ``` ```forth \ Get time components on stack time&date \ Stack: sec min hour day month year ``` ```forth \ Get current hour get-hour . \ Output: 14 ``` ```forth \ Get current minute get-minute . \ Output: 30 ``` ```forth \ Update weather from API update-weather ``` ```forth \ Weather code is stored in variable weather-code @ . ``` ```forth \ European Air Quality Index eaiq @ . ``` -------------------------------- ### Forth: Text-to-Speech Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Make the Nabaztag speak a given string using text-to-speech. ```forth \ Say something (text-to-speech) "Hello World" say ``` -------------------------------- ### Task Management API Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for managing background tasks on the Nabaztag device. ```APIDOC ## START-TASK ### Description Starts a new task with the given name, delay, and text to execute. ### Parameters - **text** (string) - Required - The code or text to execute - **delay** (number) - Required - Delay before execution - **name** (string) - Required - Name of the task ## RESUME-TASK ### Description Resume the task with the given task id. ### Parameters - **task-id** (number) - Required - The ID of the task to resume ## STOP-TASK ### Description Stop the task with the given task id. ### Parameters - **task-id** (number) - Required - The ID of the task to stop ## SUSPEND-TASK ### Description Suspend the task with the given task id. ### Parameters - **task-id** (number) - Required - The ID of the task to suspend ``` -------------------------------- ### Forth: LED Override Words Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Set LED colors and effects using Forth variables. Colors are hex strings. Use -1 to clear overrides. Breathing effect can be toggled. ```forth \ Override left LED to red "#ff0000" led-left ! ``` ```forth \ Override nose LED to green "#00ff00" led-nose ! ``` ```forth \ Override base LED to blue "#0000ff" led-base ! ``` ```forth \ Enable/disable base LED breathing effect (1=on, 0=off) 1 led-base-breathing ! ``` ```forth \ Clear LED override (use -1 or "-1") "-1" led-left ! ``` ```forth \ Available LED variables: \ led-nose, led-left, led-center, led-right, led-base ``` -------------------------------- ### Python Nabaztag API Client Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Python functions to interact with the Nabaztag device's HTTP API for status, ear control, LED color, and speech. ```python import urllib.request import json NABAZTAG_IP = "192.168.1.100" def nabaztag_request(endpoint, params=None): """Send a request to the Nabaztag API""" url = f"http://{NABAZTAG_IP}/{endpoint}" if params: url += "?" + "&".join(f"{k}={v}" for k, v in params.items()) req = urllib.request.Request(url) with urllib.request.urlopen(req, timeout=10) as response: if response.status == 200: return json.loads(response.read()) return None def get_status(): """Get current device status""" return nabaztag_request("status") def set_ears(left_pos, right_pos, direction=0): """Set both ear positions""" nabaztag_request("left", {"p": left_pos, "d": direction}) nabaztag_request("right", {"p": right_pos, "d": direction}) def set_led_color(led, color): """Set LED color (led: n/l/c/r/b, color: #rrggbb or -1)""" import urllib.parse data = urllib.parse.urlencode({led: color}).encode() req = urllib.request.Request(f"http://{NABAZTAG_IP}/leds", data=data, method='POST') urllib.request.urlopen(req, timeout=10) def speak(text): """Text to speech""" import urllib.parse nabaztag_request("say", {"t": urllib.parse.quote(text)}) def execute_forth(code): """Execute Forth code and return result""" import urllib.parse data = urllib.parse.urlencode({"c": code}).encode() req = urllib.request.Request(f"http://{NABAZTAG_IP}/forth", data=data, method='POST') with urllib.request.urlopen(req, timeout=10) as response: return json.loads(response.read()) # Usage examples if __name__ == "__main__": # Get device status status = get_status() print(f"Device sleeping: {status['sleep_state']}") # Wake up and greet nabaztag_request("wakeup") speak("Good morning!") # Set ears to alert position set_ears(8, 8) # Set nose LED to green set_led_color("n", "%2300ff00") # Execute Forth to get time result = execute_forth("daytime") print(f"Current time: {result['output']}") ``` -------------------------------- ### Control Sleep State Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Toggles the device sleep state, which influences LED behavior and audio playback. ```bash # Put the rabbit to sleep curl http://192.168.1.100/sleep # Wake up the rabbit curl http://192.168.1.100/wakeup ``` -------------------------------- ### Control Flow Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for controlling the execution flow of Forth programs. ```APIDOC ## Control Flow Commands ### IF **Description**: Begin a conditional. Compiles a conditional jump to the matching ELSE or THEN. **Method**: N/A (Forth word) **Endpoint**: N/A ### ELSE **Description**: Begin the else part of a conditional. Compiles an unconditional jump to the matching THEN. Updates the previous conditional jump to point to the instruction after the ELSE. **Method**: N/A (Forth word) **Endpoint**: N/A ### ENDCASE **Description**: End a case statement. **Method**: N/A (Forth word) **Endpoint**: N/A ### ENDOF **Description**: End a case option. **Method**: N/A (Forth word) **Endpoint**: N/A ### OF **Description**: Begin a case option. **Method**: N/A (Forth word) **Endpoint**: N/A ``` -------------------------------- ### Play Audio Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Plays audio files from URLs, uses text-to-speech, or triggers built-in sounds. HTTPS URLs are not supported. ```bash # Play a WAV/MP3 from URL curl "http://192.168.1.100/play?u=http://example.com/sound.mp3" # Text to speech (uses Google Translate TTS) curl "http://192.168.1.100/say?t=Hello%20World" # Play built-in sounds curl http://192.168.1.100/communication # Communication sound curl http://192.168.1.100/ack # Acknowledgment sound curl http://192.168.1.100/abort # Abort sound curl http://192.168.1.100/ministop # Mini-stop sound ``` -------------------------------- ### Nabaztag Hardware Event Hooks (Forth) Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Defines callback functions for hardware events such as button clicks, ear movements, and RFID detection. These hooks trigger specific actions on the Nabaztag device. ```forth \ Button click hook - called on single click : on-click ( -- ) nil "time=" :: time-ms :: str-join \ payload nil server-url @ :: "/hooks/click.php" :: str-join \ url http-post drop drop ; \ Double click hook : on-dbl-click ( -- ) play-midi-ack nil "time=" :: time-ms :: str-join nil server-url @ :: "/hooks/dblclick.php" :: str-join http-post drop drop ; \ Ear movement hook - called when ears are manually moved : on-ears ( -- ) play-midi-acquired nil "left=" :: left-ear-position :: "&right=" :: right-ear-position :: str-join nil server-url @ :: "/hooks/ears.php" :: str-join http-post drop drop ; \ Hourly chime hook : on-time ( -- ) sleeping? invert if nil server-url @ :: "/config/clock/" :: language @ :: "/" :: get-hour :: "/" :: 6 random 1 + :: ".mp3" :: str-join play-url then ; \ RFID tag detection hook : on-rfid ( rfid -- ) >r nil "tag=" :: >r :: str-join nil server-url @ :: "/hooks/rfid.php" :: str-join http-post drop drop ; ``` -------------------------------- ### Nabaztag Weather Data Fetching (Forth) Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Fetches weather and air quality data from open-meteo API. Includes functions to convert weather codes to displayable information and update the device's weather and pollution status. ```forth variable weather-code variable eaiq \ European Air Quality Index \ Convert weather code to info display code : meteo>info ( n -- n ) dup 0 = if drop 0 exit then \ clear dup 3 <= if drop 1 exit then \ partly cloudy dup 45 48 between if drop 2 exit then \ fog dup 51 67 between if drop 3 exit then \ rain/drizzle dup 71 75 between if drop 4 exit then \ snow dup 80 82 between if drop 3 exit then \ rain showers dup 95 99 between if drop 5 exit then \ thunderstorm drop nil ; \ Update weather and air quality from APIs : update-weather ( -- ) latitude @ count 0<> longitude @ count 0<> and if \ Fetch weather nil "http://api.open-meteo.com/v1/forecast?latitude=" :: latitude @ :: "&longitude=" :: longitude @ :: "&daily=weathercode&timezone=GMT&forecast_days=1" :: str-join http-get drop json-parse "daily.weathercode[0]" json-get dup weather-code ! meteo>info info-weather ! \ Fetch air quality nil "http://air-quality-api.open-meteo.com/v1/air-quality?latitude=" :: latitude @ :: "&longitude=" :: longitude @ :: "¤t=european_aqi&forecast_days=1" :: str-join http-get drop json-parse "current.european_aqi" json-get dup eaiq ! dup nil <> if eaiq>info info-pollution ! then then ; ``` -------------------------------- ### Logical Operations Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for performing logical operations. ```APIDOC ## Logical Operations ### INVERT **Description**: Logical NOT. **Parameters**: ( n -- flag ) ### OR **Description**: Logical OR. **Parameters**: ( n1 n2 -- flag ) ``` -------------------------------- ### Forth: Sleep and Wake Control Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Manage the device's sleep state using Forth commands. 'sleeping?' returns a flag indicating the current state. ```forth \ Put the rabbit to sleep sleep ``` ```forth \ Wake up the rabbit wake-up ``` ```forth \ Check if currently sleeping (returns flag) sleeping? . \ Output: 0 (awake) or -1 (sleeping) ``` ```forth \ Check if current time is in sleep interval sleeping-time? . ``` -------------------------------- ### Check Unread Emails and Control Nabaztag Nose LED (Python) Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Python script to check for unread emails via IMAP and control the Nabaztag's nose LED accordingly. Requires email credentials and the Nabaztag's IP address. ```python #!/usr/bin/python # examples/check_mail.py - Turn on nose when you have unread emails import socket import urllib.request import imaplib # Configuration username = 'your-email@gmail.com' password = 'your-app-password' server = 'imap.gmail.com' port = 993 abaztag_address = '192.168.1.100' # Set socket timeout timeout = 10 socket.setdefaulttimeout(timeout) # Connect to IMAP server imap_server = imaplib.IMAP4_SSL(server, port) imap_server.login(username, password) imap_server.select('INBOX') # Count unread emails status, response = imap_server.status('INBOX', "(UNSEEN)") unreadcount = int(response[0].split()[2].strip(').,]")) # Set nose LED based on email count if unreadcount: cmd = "nose?v=1" # Turn on the nose (1 blink pattern) else: cmd = "nose?v=0" # Turn off the nose # Send command to Nabaztag base_url = f'http://{nabaztag_address}/' req = urllib.request.Request(base_url + cmd) urllib.request.urlopen(req) print(f"Unread emails: {unreadcount}, nose LED: {{'on' if unreadcount else 'off'}}") ``` -------------------------------- ### Load Nabaztag Device Status on Page Load Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/index.html Fetches the current status of the Nabaztag device upon page load. Populates various form fields and display elements with the retrieved status information, including MAC address, revision, language, and sensor/LED states. ```javascript async function onLoad() { const response = await fetch('/status'); const status = await response.json(); document.getElementById("macAddress").innerHTML = status.wifi.mac; document.getElementById("revision").innerHTML = status.rev; document.querySelector('#langField').value = status.language; document.querySelector('#taichiField').value = status.taichi_freq; document.querySelector('#dstField').value = status.time.dst; document.getElementById("latitudeField").value = status.latitude; document.getElementById("longitudeField").value = status.longitude; document.getElementById("wakeUpField").value = status.wake_up; document.getElementById("goToBedField").value = status.go_to_bed; document.querySelector('#weatherField').value = status.info.weather; document.querySelector('#pollutionField').value = status.info.pollution; document.querySelector('#trafficField').value = status.info.traffic; document.querySelector('#service4Field').value = status.info.service4; document.querySelector('#service5Field').value = status.info.service5; document.querySelector('#stockField').value = status.info.stock; document.querySelector('#emailsField').value = status.info.emails; document.querySelector('#noseField').value = status.info.messages; document.getElementById("ledNoseField").value = formatColor(status.leds.overrides.nose); document.getElementById("ledLeftField").value = formatColor(status.leds.overrides.left); document.getElementById("ledMiddleField").value = formatColor(status.leds.overrides.middle); document.getElementById("ledRightField").value = formatColor(status.leds.overrides.right); document.getElementById("ledBaseField").value = formatColor(status.leds.overrides.base); document.getElementById("ledBaseBreathingField").value = status.leds.base_breathing ? 1 : 0; document.getElementById("openAPI").href += "?openapi_url=http%3A%2F%2F" + window.location.host + "%2Fopenapi.yaml"; loadTimezones(status.time.city_code); } document.addEventListener('DOMContentLoaded', onLoad); ``` -------------------------------- ### Connect to Nabaztag Forth Interpreter via Telnet Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Connect to the Nabaztag device using Telnet to access the interactive Forth system. The escape character is '^]'. ```bash $ telnet 192.168.79.15 Trying 192.168.79.15... Connected to 192.168.79.15. Escape character is '^]'. *** ServerlessNabaztag *** $Rev: 2025-12-20T07:44:49$ Welcome to the interactive Forth system. Type 'words' to see available words. Type 'quit' to exit the interpreter. [0] > taichi [0] > ``` -------------------------------- ### Forth: Display Current Time Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Display the current time on the Nabaztag. ```forth \ Display current time daytime ``` -------------------------------- ### Nabaztag Scheduled Tasks (Forth) Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Defines scheduled tasks for the Nabaztag, including playing surprise sounds and Tai Chi exercises. The main crontab function is called periodically to check and execute these tasks. ```forth variable crontab-last-minute variable surprise-next-time 120 60 * constant surprise-delay \ 2 hours average \ Surprise action - plays random sound : surprise ( -- ) sleeping? invert if nil server-url @ :: "/config/surprise/" :: language @ :: "/" :: 299 random 1 + :: ".mp3" :: str-join play-url then ; \ Tai Chi exercise - plays choreography : taichi ( -- ) sleeping? invert if nil server-url @ :: "/config/chor/taichi.chor" :: str-join http-get drop play-chor then ; \ Main crontab function (called periodically) : crontab ( -- ) time? if get-minute dup crontab-last-minute @ <> if dup crontab-last-minute ! sleeping? sleeping-time? invert and if wake-up then dup 0 = if on-time then \ hourly chime 30 = if on-halftime then \ half-hour chime surprise-time? if surprise calc-surprise else taichi-time? if taichi calc-taichi then then sleeping? invert sleeping-time? and if sleep then else drop then then ; ``` -------------------------------- ### Telnet Connection to Nabaztag Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Connect to the Nabaztag device via Telnet on port 22 for interactive Forth programming. This allows direct execution of Forth commands. ```bash # Connect to Nabaztag via Telnet $ telnet 192.168.1.100 Trying 192.168.1.100... Connected to 192.168.1.100. Escape character is '^]'. *** ServerlessNabaztag *** $Rev: 2025-12-20T07:44:49$ Welcome to the interactive Forth system. Type 'words' to see available words. Type 'quit' to exit the interpreter. [0] > ears . . 0 0 [0] > left-ear forward 10 move-ear [0] > "Hello from Telnet" say [0] > sleeping? [1] > . 0 [0] > taichi [0] > quit Connection closed by foreign host. ``` -------------------------------- ### Forth: Sleep Rabbit Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Command to put the Nabaztag to sleep. ```forth \ Put the rabbit to sleep sleep ``` -------------------------------- ### Network Operations Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/words.txt Commands for performing HTTP requests and retrieving network information. ```APIDOC ## Network Operations ### HTTP-GET **Description**: Perform an HTTP GET request and return the content as a string. HTTPS is not supported. **Parameters**: ( url -- content header ) ### HTTP-POST **Description**: Perform an HTTP POST request and return the content as a string. HTTPS is not supported. **Parameters**: ( payload url -- content header ) ### IP **Description**: Push the IP address of the WIFI interface onto the stack. **Parameters**: ( -- ip ) ### MAC **Description**: Push the MAC address of the WIFI interface onto the stack. **Parameters**: ( -- mac ) ``` -------------------------------- ### Format Color Value for LEDs Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/index.html Converts a numerical color value to a hexadecimal string format, prepending '#' and padding with zeros. Returns -1 if the input is -1. ```javascript function formatColor(c) { if (c == -1) return -1; return "#" + Number(c).toString(16).padStart(6, '0'); } ``` -------------------------------- ### Forth: Override Left LED Color Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Override the left LED color of the Nabaztag. Accepts a hex color string. ```forth \ Override the left LED to red color "#ff0000" led-left ! ``` -------------------------------- ### Control Nabaztag via HTTP API Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Send HTTP requests to control the Nabaztag device. This is useful for external scripts or programs. ```bash $ curl http://nabaztag/wakeup ``` -------------------------------- ### Load Timezones for City Selection Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/index.html Fetches timezone data and populates a select element. Sets the selected value based on the provided city code. ```javascript async function loadTimezones(city_code) { const response = await fetch('/timezones'); const timezones = await response.json(); const select = document.getElementById('cityCodeField'); select.innerHTML = ''; // Populate the select timezones.forEach(tz => { const option = document.createElement('option'); option.value = tz.code; option.textContent = tz.name; select.appendChild(option); }); // Set the selected value document.querySelector('#cityCodeField').value = city_code; } ``` -------------------------------- ### Forth: Move Left Ear Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Control the Nabaztag's left ear. Use 'forward' or 'backward' followed by a position value. ```forth \ Move the left ear forward to position 10 left-ear forward 10 move-ear ``` -------------------------------- ### Forth: Display Ear Positions Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Display the current positions of the Nabaztag's ears. ```forth \ Display current ear positions ears . . ``` -------------------------------- ### Forth: Move Right Ear Source: https://github.com/andreax79/serverlessnabaztag/blob/main/README.md Control the Nabaztag's right ear. Use 'forward' or 'backward' followed by a position value. ```forth \ Move the right ear backward to position 5 right-ear backward 5 move-ear ``` -------------------------------- ### Forth: Ear Control Words Source: https://context7.com/andreax79/serverlessnabaztag/llms.txt Control the Nabaztag's ears using Forth commands. Constants for ear selection and direction are available. Positions range from 0 to 16. ```forth \ Move left ear forward to position 10 left-ear forward 10 move-ear ``` ```forth \ Move right ear backward to position 5 right-ear backward 5 move-ear ``` ```forth \ Get current ear positions (returns left right on stack) ears . . \ Output: 10 5 ``` ```forth \ Constants available: \ left-ear = 0, right-ear = 1 \ forward = 0, backward = 1 \ Positions: 0-16 ``` -------------------------------- ### Clear Device Information Fields Source: https://github.com/andreax79/serverlessnabaztag/blob/main/vl/index.html Resets various device information fields to default values. This function is typically called to clear current status displays. ```javascript async function clearInfo() { fetch('/clear'); document.querySelector('#weatherField').value=-1; document.querySelector('#pollutionField').value=-1; document.querySelector('#trafficField').value=-1; document.querySelector('#service4Field').value=-1; document.querySelector('#service5Field').value=-1; document.querySelector('#stockField').value=-1; document.querySelector('#emailsField').value=-1; document.querySelector('#noseField').value=0; } ```