Transmitting a 2D array to the server and retrieving it using JavaScript

I used to send data to the server using a one-dimensional array in C Arduino language. Now, I need to figure out how to send a two-dimensional array instead.


typedef struct {
  String Name;
  String addr;
  String ttl;
}officeKownNetworks;
officeKownNetworks officeDevice;

JSONVar readings;
String KnownMacDetails() {
        while(true) {
            readings["addrDeviceUser"] = officeDevice.Name;
            readings["addr"] = officeDevice.addr;
            String jsonString = JSON.stringify(readings);
            return jsonString;
        }
        
};

Previously, I used SPIFFS to send the data to Javascript.

server.on("/clientsniffer", HTTP_GET, [](AsyncWebServerRequest *request){
    String json = KnownMacDetails();
    request->send(200, "application/json", json);
    json = String();
  });

However, I'm now facing challenges with sending and receiving data from a two-dimensional array.

In my case, Mac addresses are stored in a loop within an array of maclist [64] [3];

How do I transmit this array data to the server and retrieve it in Javascript? What parameters should I use?

Any guidance is greatly appreciated.

While I have successfully sent a one-dimensional array through JSON, I now seek assistance on handling a two-dimensional array's communication between the server and Javascript.

Answer №1

I have not had the opportunity to work with that specific library, but a potential implementation could look something like this:

String ExtractMacDetails() {
    JSONVar macDetailsArray;
    for( int index = 0; index < 64; index++ ){
        JSONVar entry;
        entry["mac"]    = maclist[index][0];
        entry["ttl"]    = maclist[index][1];
        entry["status"] = maclist[index][2];

        macDetailsArray[index] = entry;
    }
    return JSON.stringify(macDetailsArray);  
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can we modify the styling of elements in Angular based on an object property?

I have a class named Task with the following properties: export class Task { name: string; state: number; } Within my component.ts file, I have an array of objects consisting of instances of the Task class (tasks). When displaying them in the tem ...

Concerns surrounding obtaining a response while using the $.get() method

$('#requestButton').click(function() { $.get('ajax.php', function(data) { alert(data); }); }); Why is the alert() not appearing after the click event? ...

Utilize Google Place Autocomplete to restrict input to only addresses recommended by autocomplete suggestions

My application includes an input field for users to enter an address, with the help of Google's Place Autocomplete feature for address suggestions. The location field is mandatory. I aim to restrict users from submitting the form with an address that ...

Routing WebSocket connections with Node.js

Currently, I am in the process of developing a chat application for my company which will run on node js with websocket (ws). The app is designed to cater to various departments within the organization, each with its own set of users. My goal is to ensure ...

Performing an AJAX request to the database when a change occurs, prior to submitting the

In my user setup/create form, I am including a field for the users' license/certification number which needs to be validated and returned to a specific DIV Onchange before the form is submitted. I have heard that using AJAX POST is the way to achieve ...

Rotating the camera by 45 degrees around the z-axis is successful, however the same cannot be said for

I've been struggling with setting up an orthographic camera in C++ and facing some challenges with getting the rotation right. Rotating the camera around the z-axis by 45 degrees works as expected (where the model is defined from -0.5f to 0.5f). htt ...

Struggling with coding an array of images in Angular JS

I am having trouble displaying the images as thumbnails and full images for each "gem." The Angular tutorial I followed did not provide enough detail on how to do this. Here is my HTML code: <!DOCTYPE html> <html ng-app="store"> <head> ...

Does std::deque truly provide thread safety?

Despite the supposed thread safety of std::deque according to literature, my personal experience contradicts this. Currently using VS 2010, I have multiple threads running identical code but encountering errors when accessing a deque structure. Each thread ...

Interoperability between Windows and Linux through cross-platform dynamic linking is essential for seamless

Managing cross-platform compatibility between Windows and Linux has been a successful endeavor thanks to the use of Cmake and Boost in my application. Now, I face the challenge of linking to a .dll that was specifically written for Windows. Postponing the ...

How can I display a popup window within an iframe on a separate full page?

I am facing an issue while creating an HTML table using AngularJS with a popup. The problem is that I want the popup window, which shows a graph, to open up on the entire page instead of in a specific div. My desired output should look like this: https://i ...

Appreciating the Importance of Generator Functions in JavaScript

Can someone help me understand the practicality of using generator functions in JavaScript? I know they can be used for iterating through custom data types, but I'm not entirely convinced that they are superior to standard iteration techniques. For a ...

What is the best way to read and process a JSON file similar to this one

I want to extract information from this specific JSON document. The desired output would have the second column as Canonical SMILES and the third column as Isomeric SMILES. 5317139<TAB><TAB>CCCC=C1C2=C(C3C(O3)CC2)C(=O)O1<TAB>CCC/C=C&bso ...

An issue encountered when utilizing the express routes method within a NodeJS application

I'm running into an issue while attempting to restructure my NodeJS API, specifically when it comes to importing my routes. The error I'm encountering is as follows: /Users/pato/Documents/nodejs-bp-api/node_modules/express/lib/router/index.js:13 ...

The Bootstrap modal stubbornly refuses to close even after resetting the HTML body

I am having an issue with my bootstrap modal where the closeModal button is not functioning properly after the printModal button has been clicked. The modal does not close as expected. Step 1: Click on the printModal button after the modal pops up (this w ...

Implementing Dynamic Weight-based Pricing with CodeIgniter and AJAX

My shopping cart website utilizes ajax and Codeigniter to add products without reloading the page. Originally, I displayed a single net weight for each product. However, I recently switched to multiple net weights for the same product. Unfortunately, I am ...

Instructions on incorporating a new column into an already existing pickerview

I am in need of a multi-component pickerview, but I am facing the challenge of adding a new column to the far left of it. Currently, it only consists of two out of the three components that I require. Below is the existing code where I have attempted vario ...

Adjustments to CSS resulting from modifications made with react-router-dom

Currently working on a petite website using create-react-app combined with sass, I aim to have the ability to alter the styling of Navbar.Brand. This includes the feature to conceal it when the homepage is in view, depending on the URL path. I believe an ...

Discovering the final message in a conversation through the use of group by

https://i.sstatic.net/ij32q.png Initially, I thought it would be a simple task, but I ran into difficulties while trying to extract the conversation list using group by sender receiver array. The snapshot of the database is shown above. I have attempted ...

Update of component triggered only upon double click

I'm encountering an issue with my parent component passing products and their filters down to a subcomponent as state. Whenever I add a filter, I have to double click it for the parent component to rerender with the filtered products. I know this is d ...

Choose all elements by their class except for a particular container defined by the parent element's ID

Can you provide an example of translating the function below into utilizing the .not method (or not selector)? $(".CLASS").filter(function(i, e){ return (e.parentNode.id != "ID"); } ...