Skip to content

Commit

Permalink
Merge pull request #1 from Mobsya/main
Browse files Browse the repository at this point in the history
documentation
  • Loading branch information
andresvcc authored May 8, 2024
2 parents 85814f7 + 05e5338 commit c34fedb
Show file tree
Hide file tree
Showing 4,157 changed files with 1,243,064 additions and 153 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ With the Thymio_2_plus Turborepo, developers and enthusiasts have access to a wi

# Documentation

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.
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.


# Getting Started with Thymio Suite V3 Turborepo
# Getting Started with Thymio2+ Turborepo

<br />

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { LoginTokenResponse } from '@/types';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { act } from 'react-test-renderer';
import tough, { Cookie } from 'tough-cookie';
import { t } from 'xstate';
import { Sid } from '..';

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

// fusione macs and devices by id key
devices.forEach((device: { ip: string; id: string; mac: string; active: boolean }) => {
const deviceByMac = macs?.find((mac: { mac: string; id: string }) => mac.id === device.id);
if (device && deviceByMac) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Meta, Description } from '@storybook/addon-docs'

<Meta
title="HTTP CAlls/get all devices"
parameters={{
viewMode: 'docs',
previewTabs: {
canvas: { hidden: true }
},
}}
/>

# Get All Devices

### API CALL: `getDevices`

This function retrieves the devices connected to the Thymio2+ router, particularly tablets.

#### Parameters:

- `sid`: A `Sid` object containing the session ID required for authentication.

#### Returns:

- A Promise resolving to an array of devices connected to the router. Each device object contains the following properties:
- `ip`: The IP address of the device.
- `id`: The unique identifier of the device.
- `mac`: The MAC address of the device.
- `active`: A boolean indicating whether the device is currently active or not.

#### Example Usage:

```javascript
import { Sid } from '..';

// Sample session ID
const sid: Sid = 'sampleSessionID';

async function fetchDevices() {
try {
const devices = await getDevices({ sid });
console.log(devices);
} catch (error) {
console.error('Error fetching devices:', error.message);
}
}

fetchDevices();
```

#### Details:

1. **Function**: `matchesThymioPattern`

- Description: Checks if the input string matches the pattern 'Thymio-XXXXXX.lan'.
- Parameters: `str` - The input string to be tested.
- Returns: A boolean indicating whether the input string matches the pattern or not.

2. **Function**: `getDevices`

- Description: Retrieves the devices connected to the Thymio2+ router, particularly tablets.
- Parameters: An object containing the session ID (`sid`).
- Returns: A Promise resolving to an array of device objects.
- Steps:
1. Constructs the necessary HTTP request headers.
2. Fetches IP address hints from the router.
3. Fetches MAC address hints from the router.
4. Merges IP and MAC address data to form device objects.
5. Filters out devices that do not match the Thymio pattern.
- Throws: An error if fetching devices fails.

#### Important Note:

- Ensure that the `Sid` object passed to the function contains a valid session ID for authentication with the router.

#### Dependencies:

- This function relies on the `fetch` API for making HTTP requests.

#### Security Considerations:

- Ensure that the session ID (`sid`) used for authentication is obtained securely and is not exposed to unauthorized users.
- Implement proper error handling and validation to handle unexpected responses from the router.
- Use HTTPS instead of HTTP for secure communication with the router whenever possible.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Meta, Description } from '@storybook/addon-docs'

<Meta
title="HTTP CAlls/get if status"
parameters={{
viewMode: 'docs',
previewTabs: {
canvas: { hidden: true }
},
}}
/>

# Get Network Status

### API CALL: : `getIfStatus`

This function retrieves the status of the network interface from the router.

#### Parameters:

- `sid`: A `Sid` object containing the session ID required for authentication.

#### Returns:

- A Promise resolving to an object representing the status of the network interface.

#### Example Usage:

```javascript
import { Sid } from '..';

// Sample session ID
const sid: Sid = 'sampleSessionID';

async function fetchIfStatus() {
try {
const ifStatus = await getIfStatus({ sid });
console.log(ifStatus);
} catch (error) {
console.error('Error fetching interface status:', error.message);
}
}

fetchIfStatus();
```

#### Details:

1. **Function**: `getIfStatus`

- Description: Retrieves the status of the network interface from the router.
- Parameters: An object containing the session ID (`sid`).
- Returns: A Promise resolving to an object representing the status of the network interface.
- Throws: An error if fetching the interface status fails.

2. **Default Status Object**:

- Description: A default status object returned when the interface status is not found.
- Fields:
- `up`: Indicates if the interface is up.
- `pending`: Indicates if there are pending changes.
- `available`: Indicates if the interface is available.
- `autostart`: Indicates if the interface starts automatically.
- `dynamic`: Indicates if the interface is dynamic.
- `uptime`: Uptime of the interface.
- `l3_device`: Layer 3 device.
- `proto`: Protocol used.
- `device`: Device name.
- `updated`: Updated fields.
- `metric`: Metric value.
- `dns_metric`: DNS metric value.
- `delegation`: Indicates if delegation is enabled.
- `ipv4-address`: Array of IPv4 addresses.
- `ipv6-address`: Array of IPv6 addresses.
- `ipv6-prefix`: Array of IPv6 prefixes.
- `ipv6-prefix-assignment`: Array of IPv6 prefix assignments.
- `route`: Array of routes.
- `dns-server`: Array of DNS servers.
- `dns-search`: Array of DNS search domains.
- `neighbors`: Array of neighbors.
- `inactive`: Inactive status fields.
- `data`: Additional data.
- Note: This default status object is returned when the interface status is not found.

#### Dependencies:

- This function relies on the `fetch` API for making HTTP requests.

#### Security Considerations:

- Ensure that the session ID (`sid`) used for authentication is obtained securely and is not exposed to unauthorized users.
- Implement proper error handling and validation to handle unexpected responses from the router.
- Use HTTPS instead of HTTP for secure communication with the router whenever possible.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { LoginTokenResponse } from '@/types';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import tough, { Cookie } from 'tough-cookie';
import { Sid } from '..';

export async function getIfStatus({ sid }: { sid: Sid }): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Meta, Description } from '@storybook/addon-docs'

<Meta
title="HTTP CAlls/get internet status"
parameters={{
viewMode: 'docs',
previewTabs: {
canvas: { hidden: true }
},
}}
/>

# Get Internet Status

### API CALL: getInternetStatus

#### Overview
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.

#### Imports
```javascript
import axios, { AxiosRequestConfig } from 'axios';
import { Sid } from '..';
```
- **axios**: Used for making HTTP requests.
- **AxiosRequestConfig**: Type used for configuring the axios request.
- **Sid**: A type imported from the parent directory, presumably representing session ID or similar credentials.

#### Parameters
- `sid`: A session identifier of type `Sid`, required to authenticate or manage the session context for the request.

#### Returns
- **Promise of boolean**: ```Promise<boolean>``` A promise that resolves to `true` if the internet is reachable, otherwise `false`.

#### Function Logic
1. **Prepare the Request:**
- The function constructs a JSON string that includes the command to check internet connectivity by using `wget` to quietly fetch Google's homepage.
- The command will print 'true' if the fetch is successful, and 'false' otherwise.

```javascript
const data = JSON.stringify({
method: 'exec',
params: ["wget -q --spider http://www.google.com 2>/dev/null && echo 'true' || echo 'false'"],
});
```

2. **Configure the Request:**
- An axios configuration object is set up, specifying the HTTP method, URL endpoint, headers, data, and timeout for the request.

```javascript
const config: AxiosRequestConfig = {
method: 'post',
url: '/cgi-bin/luci/rpc/sys',
headers: {
'Content-Type': 'application/json',
},
data: data,
timeout: 4000,
};
```

3. **Execute the Request and Handle Response:**
- The axios library is used to send the configured request asynchronously.
- If the HTTP response status is not 200, an error is thrown.
- The function checks if the response contains 'true' within the result field to determine internet connectivity.

```javascript
const response = await axios(config);
if (response.status !== 200) {
throw new Error('Error fetching getWifiConfigFile');
}
return response.data.result.includes('true');
```

4. **Error Handling:**
- The catch block handles various errors such as axios cancellation due to timeout, server responses indicating failure, no response received, or other axios errors.
- In any error scenario, the function returns `false`, indicating no internet connectivity.

```javascript
catch (error: any) {
if (axios.isCancel(error)) {
// Request was cancelled due to timeout
return false;
} else if (error.response) {
// Server responded with an error
return false;
} else if (error.request) {
// No response was received
return false;
} else {
// Other errors
console.log('Error:', error.message);
}
return false;
}
```

#### Usage Example
```javascript
const isConnected = await getInternetStatus({ sid: yourSessionId })
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import axios, { AxiosRequestConfig } from 'axios';
import { Sid } from '..';

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

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

return response.data.result.includes('true');
} catch (error: any) {
if (axios.isCancel(error)) {
// console.log('La solicitud ha sido cancelada debido a un timeout');
return false;
} else if (error.response) {
// console.log('Error response:', error.response.data);
return false;
} else if (error.request) {
// console.log('No response received:', error.request);
return false;
} else {
console.log('Error:', error.message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { LoginTokenResponse } from '@/types';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import tough, { Cookie } from 'tough-cookie';
import { Sid } from '..';

export async function getUptime({ sid }: { sid: Sid }): Promise<number> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { LoginTokenResponse } from '@/types';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import tough, { Cookie } from 'tough-cookie';
import { Sid } from '..';

function parseStringToJson(inputString: string): any {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { LoginTokenResponse } from '@/types';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import tough, { Cookie } from 'tough-cookie';

export async function updateRootPassword({
newPassword,
sidToken,
Expand Down
2 changes: 2 additions & 0 deletions apps/thymio-suite-mobile-android/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
Loading

0 comments on commit c34fedb

Please sign in to comment.