Skip to content

Commit c34fedb

Browse files
authored
Merge pull request #1 from Mobsya/main
documentation
2 parents 85814f7 + 05e5338 commit c34fedb

File tree

4,157 files changed

+1243064
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,157 files changed

+1243064
-153
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ With the Thymio_2_plus Turborepo, developers and enthusiasts have access to a wi
99

1010
# Documentation
1111

12-
Before diving into the installation process, we highly recommend visiting the [Documentation](https://andresvcc.github.io/thymio_2_plus/?path=/docs/introduction--page). This comprehensive documentation will provide you with detailed information about the Thymio2+, its features, and how to utilize its capabilities effectively.
12+
Before diving into the installation process, we highly recommend visiting the [Documentation](https://mobsya.github.io/thymio_2_plus/?path=/docs/introduction--page). This comprehensive documentation will provide you with detailed information about the Thymio2+, its features, and how to utilize its capabilities effectively.
1313

1414

15-
# Getting Started with Thymio Suite V3 Turborepo
15+
# Getting Started with Thymio2+ Turborepo
1616

1717
<br />
1818

apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/GettingStarded.stories.mdx

+299
Large diffs are not rendered by default.

apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getAllDevicesIP:Name.ts

-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import { LoginTokenResponse } from '@/types';
2-
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
3-
import { act } from 'react-test-renderer';
4-
import tough, { Cookie } from 'tough-cookie';
5-
import { t } from 'xstate';
61
import { Sid } from '..';
72

83
function matchesThymioPattern(str: string): boolean {
9-
// Expresión regular para coincidir con el patrón 'Thymio-XXXXXX.lan'
104
const pattern = /Thymio-[a-zA-Z0-9]+\.lan/;
115
return !pattern.test(str);
126
}
@@ -60,7 +54,6 @@ export async function getDevices({ sid }: { sid: Sid }): Promise<Array<any>> {
6054
id: device[1],
6155
}));
6256

63-
// fusione macs and devices by id key
6457
devices.forEach((device: { ip: string; id: string; mac: string; active: boolean }) => {
6558
const deviceByMac = macs?.find((mac: { mac: string; id: string }) => mac.id === device.id);
6659
if (device && deviceByMac) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Meta, Description } from '@storybook/addon-docs'
2+
3+
<Meta
4+
title="HTTP CAlls/get all devices"
5+
parameters={{
6+
viewMode: 'docs',
7+
previewTabs: {
8+
canvas: { hidden: true }
9+
},
10+
}}
11+
/>
12+
13+
# Get All Devices
14+
15+
### API CALL: `getDevices`
16+
17+
This function retrieves the devices connected to the Thymio2+ router, particularly tablets.
18+
19+
#### Parameters:
20+
21+
- `sid`: A `Sid` object containing the session ID required for authentication.
22+
23+
#### Returns:
24+
25+
- A Promise resolving to an array of devices connected to the router. Each device object contains the following properties:
26+
- `ip`: The IP address of the device.
27+
- `id`: The unique identifier of the device.
28+
- `mac`: The MAC address of the device.
29+
- `active`: A boolean indicating whether the device is currently active or not.
30+
31+
#### Example Usage:
32+
33+
```javascript
34+
import { Sid } from '..';
35+
36+
// Sample session ID
37+
const sid: Sid = 'sampleSessionID';
38+
39+
async function fetchDevices() {
40+
try {
41+
const devices = await getDevices({ sid });
42+
console.log(devices);
43+
} catch (error) {
44+
console.error('Error fetching devices:', error.message);
45+
}
46+
}
47+
48+
fetchDevices();
49+
```
50+
51+
#### Details:
52+
53+
1. **Function**: `matchesThymioPattern`
54+
55+
- Description: Checks if the input string matches the pattern 'Thymio-XXXXXX.lan'.
56+
- Parameters: `str` - The input string to be tested.
57+
- Returns: A boolean indicating whether the input string matches the pattern or not.
58+
59+
2. **Function**: `getDevices`
60+
61+
- Description: Retrieves the devices connected to the Thymio2+ router, particularly tablets.
62+
- Parameters: An object containing the session ID (`sid`).
63+
- Returns: A Promise resolving to an array of device objects.
64+
- Steps:
65+
1. Constructs the necessary HTTP request headers.
66+
2. Fetches IP address hints from the router.
67+
3. Fetches MAC address hints from the router.
68+
4. Merges IP and MAC address data to form device objects.
69+
5. Filters out devices that do not match the Thymio pattern.
70+
- Throws: An error if fetching devices fails.
71+
72+
#### Important Note:
73+
74+
- Ensure that the `Sid` object passed to the function contains a valid session ID for authentication with the router.
75+
76+
#### Dependencies:
77+
78+
- This function relies on the `fetch` API for making HTTP requests.
79+
80+
#### Security Considerations:
81+
82+
- Ensure that the session ID (`sid`) used for authentication is obtained securely and is not exposed to unauthorized users.
83+
- Implement proper error handling and validation to handle unexpected responses from the router.
84+
- Use HTTPS instead of HTTP for secure communication with the router whenever possible.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { Meta, Description } from '@storybook/addon-docs'
2+
3+
<Meta
4+
title="HTTP CAlls/get if status"
5+
parameters={{
6+
viewMode: 'docs',
7+
previewTabs: {
8+
canvas: { hidden: true }
9+
},
10+
}}
11+
/>
12+
13+
# Get Network Status
14+
15+
### API CALL: : `getIfStatus`
16+
17+
This function retrieves the status of the network interface from the router.
18+
19+
#### Parameters:
20+
21+
- `sid`: A `Sid` object containing the session ID required for authentication.
22+
23+
#### Returns:
24+
25+
- A Promise resolving to an object representing the status of the network interface.
26+
27+
#### Example Usage:
28+
29+
```javascript
30+
import { Sid } from '..';
31+
32+
// Sample session ID
33+
const sid: Sid = 'sampleSessionID';
34+
35+
async function fetchIfStatus() {
36+
try {
37+
const ifStatus = await getIfStatus({ sid });
38+
console.log(ifStatus);
39+
} catch (error) {
40+
console.error('Error fetching interface status:', error.message);
41+
}
42+
}
43+
44+
fetchIfStatus();
45+
```
46+
47+
#### Details:
48+
49+
1. **Function**: `getIfStatus`
50+
51+
- Description: Retrieves the status of the network interface from the router.
52+
- Parameters: An object containing the session ID (`sid`).
53+
- Returns: A Promise resolving to an object representing the status of the network interface.
54+
- Throws: An error if fetching the interface status fails.
55+
56+
2. **Default Status Object**:
57+
58+
- Description: A default status object returned when the interface status is not found.
59+
- Fields:
60+
- `up`: Indicates if the interface is up.
61+
- `pending`: Indicates if there are pending changes.
62+
- `available`: Indicates if the interface is available.
63+
- `autostart`: Indicates if the interface starts automatically.
64+
- `dynamic`: Indicates if the interface is dynamic.
65+
- `uptime`: Uptime of the interface.
66+
- `l3_device`: Layer 3 device.
67+
- `proto`: Protocol used.
68+
- `device`: Device name.
69+
- `updated`: Updated fields.
70+
- `metric`: Metric value.
71+
- `dns_metric`: DNS metric value.
72+
- `delegation`: Indicates if delegation is enabled.
73+
- `ipv4-address`: Array of IPv4 addresses.
74+
- `ipv6-address`: Array of IPv6 addresses.
75+
- `ipv6-prefix`: Array of IPv6 prefixes.
76+
- `ipv6-prefix-assignment`: Array of IPv6 prefix assignments.
77+
- `route`: Array of routes.
78+
- `dns-server`: Array of DNS servers.
79+
- `dns-search`: Array of DNS search domains.
80+
- `neighbors`: Array of neighbors.
81+
- `inactive`: Inactive status fields.
82+
- `data`: Additional data.
83+
- Note: This default status object is returned when the interface status is not found.
84+
85+
#### Dependencies:
86+
87+
- This function relies on the `fetch` API for making HTTP requests.
88+
89+
#### Security Considerations:
90+
91+
- Ensure that the session ID (`sid`) used for authentication is obtained securely and is not exposed to unauthorized users.
92+
- Implement proper error handling and validation to handle unexpected responses from the router.
93+
- Use HTTPS instead of HTTP for secure communication with the router whenever possible.

apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getIfstatus.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { LoginTokenResponse } from '@/types';
2-
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
3-
import tough, { Cookie } from 'tough-cookie';
41
import { Sid } from '..';
52

63
export async function getIfStatus({ sid }: { sid: Sid }): Promise<any> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { Meta, Description } from '@storybook/addon-docs'
2+
3+
<Meta
4+
title="HTTP CAlls/get internet status"
5+
parameters={{
6+
viewMode: 'docs',
7+
previewTabs: {
8+
canvas: { hidden: true }
9+
},
10+
}}
11+
/>
12+
13+
# Get Internet Status
14+
15+
### API CALL: getInternetStatus
16+
17+
#### Overview
18+
The `getInternetStatus` function checks if the device has an active internet connection by attempting to reach Google's homepage. It returns a boolean value indicating whether the internet is accessible.
19+
20+
#### Imports
21+
```javascript
22+
import axios, { AxiosRequestConfig } from 'axios';
23+
import { Sid } from '..';
24+
```
25+
- **axios**: Used for making HTTP requests.
26+
- **AxiosRequestConfig**: Type used for configuring the axios request.
27+
- **Sid**: A type imported from the parent directory, presumably representing session ID or similar credentials.
28+
29+
#### Parameters
30+
- `sid`: A session identifier of type `Sid`, required to authenticate or manage the session context for the request.
31+
32+
#### Returns
33+
- **Promise of boolean**: ```Promise<boolean>``` A promise that resolves to `true` if the internet is reachable, otherwise `false`.
34+
35+
#### Function Logic
36+
1. **Prepare the Request:**
37+
- The function constructs a JSON string that includes the command to check internet connectivity by using `wget` to quietly fetch Google's homepage.
38+
- The command will print 'true' if the fetch is successful, and 'false' otherwise.
39+
40+
```javascript
41+
const data = JSON.stringify({
42+
method: 'exec',
43+
params: ["wget -q --spider http://www.google.com 2>/dev/null && echo 'true' || echo 'false'"],
44+
});
45+
```
46+
47+
2. **Configure the Request:**
48+
- An axios configuration object is set up, specifying the HTTP method, URL endpoint, headers, data, and timeout for the request.
49+
50+
```javascript
51+
const config: AxiosRequestConfig = {
52+
method: 'post',
53+
url: '/cgi-bin/luci/rpc/sys',
54+
headers: {
55+
'Content-Type': 'application/json',
56+
},
57+
data: data,
58+
timeout: 4000,
59+
};
60+
```
61+
62+
3. **Execute the Request and Handle Response:**
63+
- The axios library is used to send the configured request asynchronously.
64+
- If the HTTP response status is not 200, an error is thrown.
65+
- The function checks if the response contains 'true' within the result field to determine internet connectivity.
66+
67+
```javascript
68+
const response = await axios(config);
69+
if (response.status !== 200) {
70+
throw new Error('Error fetching getWifiConfigFile');
71+
}
72+
return response.data.result.includes('true');
73+
```
74+
75+
4. **Error Handling:**
76+
- The catch block handles various errors such as axios cancellation due to timeout, server responses indicating failure, no response received, or other axios errors.
77+
- In any error scenario, the function returns `false`, indicating no internet connectivity.
78+
79+
```javascript
80+
catch (error: any) {
81+
if (axios.isCancel(error)) {
82+
// Request was cancelled due to timeout
83+
return false;
84+
} else if (error.response) {
85+
// Server responded with an error
86+
return false;
87+
} else if (error.request) {
88+
// No response was received
89+
return false;
90+
} else {
91+
// Other errors
92+
console.log('Error:', error.message);
93+
}
94+
return false;
95+
}
96+
```
97+
98+
#### Usage Example
99+
```javascript
100+
const isConnected = await getInternetStatus({ sid: yourSessionId })
101+
```

apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getInternetStatus.ts

-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import axios, { AxiosRequestConfig } from 'axios';
22
import { Sid } from '..';
33

44
export async function getInternetStatus({ sid }: { sid: Sid }): Promise<boolean> {
5-
// Preparar el cuerpo de la solicitud y las cabeceras
65
const data = JSON.stringify({
76
method: 'exec',
87
params: ["wget -q --spider http://www.google.com 2>/dev/null && echo 'true' || echo 'false'"],
@@ -21,21 +20,17 @@ export async function getInternetStatus({ sid }: { sid: Sid }): Promise<boolean>
2120
try {
2221
const response = await axios(config);
2322

24-
// Verificar el estado de la respuesta
2523
if (response.status !== 200) {
2624
throw new Error('Error fetching getWifiConfigFile');
2725
}
2826

2927
return response.data.result.includes('true');
3028
} catch (error: any) {
3129
if (axios.isCancel(error)) {
32-
// console.log('La solicitud ha sido cancelada debido a un timeout');
3330
return false;
3431
} else if (error.response) {
35-
// console.log('Error response:', error.response.data);
3632
return false;
3733
} else if (error.request) {
38-
// console.log('No response received:', error.request);
3934
return false;
4035
} else {
4136
console.log('Error:', error.message);

apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getUptime.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { LoginTokenResponse } from '@/types';
2-
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
3-
import tough, { Cookie } from 'tough-cookie';
41
import { Sid } from '..';
52

63
export async function getUptime({ sid }: { sid: Sid }): Promise<number> {

apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/getWifiStatus.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { LoginTokenResponse } from '@/types';
2-
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
3-
import tough, { Cookie } from 'tough-cookie';
41
import { Sid } from '..';
52

63
function parseStringToJson(inputString: string): any {

apps/openwrt-config-dashboard/src/hooks/useLuciRCPjsonClient/fetchCalls/updateRootPassword.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import { LoginTokenResponse } from '@/types';
2-
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
3-
import tough, { Cookie } from 'tough-cookie';
4-
51
export async function updateRootPassword({
62
newPassword,
73
sidToken,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

0 commit comments

Comments
 (0)