Hi!
I would just like to seek help on the following codes regarding the Ciao Library.
My project is a Wi-Fi controlled Robot using a JoyStick Controller.
The client side contains a Potentiometer at A0 and A1.
The server side contains a Motor Driver Shield for Two DC Motors[\b] with the following fixed pin configurations:
- Pin 8 - Direction of Motor A
- Pin 9 - Speed of Motor A, PWM
- Pin 10 - Speed of Motor B, PWM
- Pin 11 - Direction of Motor B
Motor A has the Left Wheel, Motor B has the Right Wheel.
Here's the code for my Client Side:
```
**#include <Wire.h>
#include <UnoWiFiDevEd.h>
#define CONNECTOR "rest"
#define SERVER_ADDR "192.168.1.34"
String command;
int xaxis, yaxis;
void setup() {
Ciao.begin();
Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/initialization/");
Ciao.print("BEGIN TRANSMISSION\n");
// Serial.begin(9600);
}
void loop() {
xaxis = map(analogRead(A0), 0, 1000, -1, 1);
yaxis = map(analogRead(A1), 0, 1000, -1, 1);
// Serial.print("X = "), Serial.print(xaxis);
// Serial.print(" | Y = "), Serial.print(yaxis), Serial.print("\n");
if (xaxis == -1) {
command = "/arduino/motor/1";//LEFT
Ciao.print("LEFT\n");
}
else if (xaxis == 1) {
command = "/arduino/motor/2";//RIGHT
Ciao.print("RIGHT\n");
}
else if (yaxis == -1) {
command = "/arduino/motor/3";//BACKWARD
Ciao.print("BACKWARD\n");
}
else if (yaxis == 1) {
command = "/arduino/motor/4";//FORWARD
Ciao.print("FORWARD\n");
}
else{
command = "/arduino/motor/0";//STOPCHASSIS
Ciao.print("STOPCHASSIS\n");
}
Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/motor");
delay(100);
}**
** **And here's the code for my Server side:** **
*/
- "/arduino/digital/13" -> digitalRead(13)
- "/arduino/digital/13/1" -> digitalWrite(13, HIGH)
- "/arduino/analog/2/123" -> analogWrite(2, 123)
- "/arduino/analog/2" -> analogRead(2)
- "/arduino/mode/13/input" -> pinMode(13, INPUT)
- "/arduino/mode/13/output" -> pinMode(13, OUTPUT)
*/
#include <Wire.h>
#include <UnoWiFiDevEd.h>
void setup(){
Wifi.begin();
Wifi.println("RECEIVING TRANSMISSION\n");
}
void loop(){
while(Wifi.available()){
Wifi.println("WIFI IS AVAILABLE.");
process(Wifi);
}
delay(100);
}
void process(WifiData client) {
String command = client.readStringUntil('/');
Wifi.println("READ COMMAND.");
if (command == "motor") {
motorCommand(client);
}
if (command == "initialization"){
initializationCommand(client);
}
}
void initializationCommand(WifiData client){
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
client.print(EOL);
return;
}
void motorCommand(WifiData client){
int value = client.parseInt();
if (value == 1){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
client.print(EOL);
return;
}
else if (value == 2){
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
client.print(EOL);
return;
}
else if (value == 3){
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
client.print(EOL);
return;
}
else if (value == 4){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
client.print(EOL);
return;
}
else if (value == 0){
digitalWrite(9, LOW);
digitalWrite(10, LOW);
client.print(EOL);
return;
}
}**
```
I can't seem to get these two working. I am just following the Sample Sketches of RestServer.ino and RestClient.ino frameworks, but I can't get both to work. I feel that I have a problem on the Server Side, and I have been tracing the problem through inserting WiFi.print("WIFI IS AVAILABLE."); at every beginning of each function. And, at the while(Wifi.available()) function, the WIFI IS AVAILABLE doesn't print out at the WIFI CONSOLE. It seems like the Server Side is not connected/does not receive what the client sends.
Since, the Client Side only requires the Ciao.write() function to transmit, based on observations, it seems like I don't get how the server works.
Please help me work out these codes! ![]()
Thank you!