Arduino to Webserver

Hi all Im wondering how to get the input of a Linear pot to a web server via JSON?

So its like this:

Linear pot ----> Arduino Analog pin ----> Arduino Script ----> Convert to 255 for 24bit ----> USB ----> output via aJSON ----> web server.

I have this so far:

#include <aJSON.h>
#include <avr/pgmspace.h>

int val = 0;         // variable to store the read value
    
void setup()  {
  // declare pin 9 to be an output:
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop()  {
 int val = analogRead(0);
val = map(val, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(9, val);  

val = analogRead(1);
val = map(val, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(10, val);

val = analogRead(2);
val = map(val, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(11, val);

val = analogRead(3);
val = map(val, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(3, val);

val = analogRead(4);
val = map(val, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(5, val);

val = analogRead(5);
val = map(val, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(6, val);


}

But that just throws out a load of errors. I have the aJSON library installed but just really stuck to what to do plus it all needs to be sent via the USB port! A little out of my depth and need some help if anyone can!

But that just throws out a load of errors. I have the aJSON library installed but just really stuck to what to do plus it all needs to be sent via the USB port! A little out of my depth and need some help if anyone can!

My crystal ball got knocked off the table by the cat. I can not longer, unfortunately, see the error messages you are getting. You'll have to help out by posting them.

The errors:

Fader_Output_to_USB.cpp: In function 'void loop()':
Fader_Output_to_USB:24: error: invalid conversion from 'int' to '__file*'
Fader_Output_to_USB:24: error: initializing argument 1 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:24: error: invalid conversion from 'int' to 'char**'
Fader_Output_to_USB:24: error: initializing argument 2 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:28: error: redeclaration of 'aJsonObject* jsonObject'
Fader_Output_to_USB:24: error: 'aJsonObject* jsonObject' previously declared here
Fader_Output_to_USB:28: error: invalid conversion from 'int' to '__file*'
Fader_Output_to_USB:28: error: initializing argument 1 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:28: error: invalid conversion from 'int' to 'char**'
Fader_Output_to_USB:28: error: initializing argument 2 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:32: error: redeclaration of 'aJsonObject* jsonObject'
Fader_Output_to_USB:24: error: 'aJsonObject* jsonObject' previously declared here
Fader_Output_to_USB:32: error: invalid conversion from 'int' to '__file*'
Fader_Output_to_USB:32: error: initializing argument 1 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:32: error: invalid conversion from 'int' to 'char**'
Fader_Output_to_USB:32: error: initializing argument 2 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:36: error: redeclaration of 'aJsonObject* jsonObject'
Fader_Output_to_USB:24: error: 'aJsonObject* jsonObject' previously declared here
Fader_Output_to_USB:36: error: invalid conversion from 'int' to '__file*'
Fader_Output_to_USB:36: error: initializing argument 1 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:36: error: invalid conversion from 'int' to 'char**'
Fader_Output_to_USB:36: error: initializing argument 2 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:40: error: redeclaration of 'aJsonObject* jsonObject'
Fader_Output_to_USB:24: error: 'aJsonObject* jsonObject' previously declared here
Fader_Output_to_USB:40: error: invalid conversion from 'int' to '__file*'
Fader_Output_to_USB:40: error: initializing argument 1 of 'aJsonObject* aJsonClass::parse(__file*, char**)'
Fader_Output_to_USB:40: error: invalid conversion from 'int' to 'char**'
Fader_Output_to_USB:40: error: initializing argument 2 of 'aJsonObject* aJsonClass::parse(__file*, char**)'

The parse function wants some kind of pointer to something, and you are passing it a constant (int). The compiler is telling you you can't do that.

Do you have a link to the JSON library?

http://interactive-matter.eu/2010/08/ajson-handle-json-with-arduino/ this is what I'm using. thanks

aJsonObject* parse(FILE* stream); //Reads from a stream
aJsonObject* parse(FILE* stream,char** filter_values); //Read from a file, but only return values include in the char* array filter_values
aJsonObject* parse(char *value); //Reads from a string

There are three forms of the parse function, none of which match what you are trying to do.

So, what are you trying to do?

What is the first value in the parse() call supposed to represent?

All im looking at doing is taking the reading from one of the 6 analog inputs that would be connected to a pot to convert that to 24 bit value then output those values a JSON. Im new to all this and that code is what I came up with from reading bits from forums but came to a wall with the JSON stuff!

If you have no idea what the first argument does, get rid of it. See if the resulting program does what you want.

I still have no idea why you want to convert to/use JSON format.

This is my updated code:

#include <aJSON.h>


#include <avr/pgmspace.h>

int fader1 = 0;
int fader2 = 0;
int fader3 = 0;
int fader4 = 0;
int fader5 = 0;
int fader6 = 0;
int up_button = 0;
int down_button = 0;

    
void setup()  {
  Serial.begin(9600);
  pinMode(7, INPUT);
  pinMode(8, INPUT);    
}

void loop()  {
 int fader1 = analogRead(0);
fader1 = map(fader1, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(fader1, 0);  

int fader2 = analogRead(1);
fader2 = map(fader2, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(fader2, 0);

int fader3 = analogRead(2);
fader3 = map(fader3, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(fader3, 0);

int fader4 = analogRead(3);
fader4 = map(fader4, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(fader4, 0);

int fader5 = analogRead(4);
fader5 = map(fader5, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(fader5, 0);

int fader6 = analogRead(5);
fader6 = map(fader6, 0, 1023, 0, 255);
aJsonObject* jsonObject = aJson.parse(fader6, 0);

 down_button = digitalRead(7);  // read input value
  if (down_button == HIGH) {         // check if the input is HIGH (button released)
  Serial.print(1);
  } else {
  Serial.print(0);
  }
   up_button = digitalRead(8);  // read input value
  if (up_button == HIGH) {         // check if the input is HIGH (button released)
  Serial.print(1);
  } else {
  Serial.print(0);
  }
}

Still gives me the errors for the JSON.

I don’t see how you don’t know what I’m meaning? Im wanting to output the data from the Arduino to a local webpage and the way everything else is handled on the pages is via JSON and would be perfect to keep everything the same! All I am asking for is advice on how to get the output of 6 pots, put them into JSON that i can then use it on the webpage.

Still gives me the errors for the JSON.

Well, of course it does. You haven't changed anything. You are still trying to call parse with invalid arguments.

The parse function is expecting to read a string of characters from somewhere.

In the first case, it expects to read from a file. You don't have a file, so you can't use that overload.

In the second case, it expects to read from a file, with some stuff filtered off. You don't have a file, so you can't use that overload.

That only leaves the third option for you to use. That overload expects you to pass the function a NULL terminated array of characters.

 int fader1 = analogRead(0);
fader1 = map(fader1, 0, 1023, 0, 255);
char buffer[20];
sprintf(buffer, "%i", fader1);
aJsonObject* jsonObject = aJson.parse(buffer);

You need to do something with the object before you overwrite it with the fader2 value.

Why do you want to work through JSON? Not what you asked, I know… but if you just want to put your data on Pachube, the “YouTube for data streams” (sort of), then see…

http://sheepdogsoftware.co.uk/sc2wy.htm

… or consider the new alternative…

www.thingspeak.com/

… which, if it works, looks like it may be more hobbyist friendly… i.e. not so “tight” with features in the free accounts. (I haven’t studied it much yet, can’t give informed review… yet.)

I think I have something that works. Although means I need to buy a Ethernet Shield. Would of preferred it to go via USB.