Hi @Juan_Antonio following yours tips I was able to achieve my goal. Thank You!
By the way I used the "webviewer" and not the "web" to do my final task. I think that req.indexOf was the real solution. I keep off the client.stop() otherwise I read the imu only for some seconds.
At the same time, I want to share with u this my code and the shortcut of my apps done with web and webviewer component. This is because, although I can use both apps, they don't work properly:
- with "webviewer" app I can't see the client.print
- with web app Each time that I push a button the result on the screen is: error 1101, unable to get a response with the specific URL: HTTP://....... and I can't see again the client.print.
Where I am wrong? WHat is better to change in your opinion?
Gracias
#include <WiFi.h>
#include "arduino_secrets.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
int Value;
int lettura;
float q0,q1,q2,q3,gx,gy,gz,norm,phi;
float radtodeg = 57296/1000;
WiFiServer server(80);
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Wire.begin();
/* Initialise the sensor /
if(!bno.begin())
{
/ There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}
delay(1000);
/* Crystal must be configured AFTER loading calibration data into BNO055. */
bno.setExtCrystalUse(true);
Serial.println("Access Point Web Server");
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDG,HIGH);
digitalWrite(LEDB,HIGH);
// by default the local IP address of will be 192.168.3.1
// you can override it with the following:
// WiFi.config(IPAddress(10, 0, 0, 1));
// The AP needs the password be at least 8 characters long
if(strlen(pass) < 8){
Serial.println("Creating access point failed");
Serial.println("The WiFi password must be at least 8 characters long");
// don't continue
while(true);
}
// print the network name (SSID);
Serial.print("Creating access point named: ");
Serial.println(ssid);
//Create the Access point
status = WiFi.beginAP(ssid, pass);
if (status != WL_AP_LISTENING) {
Serial.println("Creating access point failed");
// don't continue
while (true);
}
// wait 10 seconds for connection:
delay(10000);
// start the web server on port 80
server.begin();
// you're connected now, so print out the status
printWiFiStatus();
}
void loop() {
// compare the previous status to the current status
if (status != WiFi.status()) {
// it has changed update the variable
status = WiFi.status();
if (status == WL_AP_CONNECTED) {
// a device has connected to the AP
Serial.println("Device connected to AP");
} else {
// a device has disconnected from the AP, and we are back in listening mode
Serial.println("Device disconnected from AP");
}
}
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
String estado = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
String req = client.readStringUntil('\r');
// Make the client's request.
if (req.indexOf("ROFF") != -1) {
lettura=1;digitalWrite(LEDR, HIGH);
Serial.print("Req: ");
Serial.println(req);
estado = "LEDR OFF";
Serial.print("Estado: ");
Serial.println(estado);
client.println(estado);
} // Return status.
if (req.indexOf("RON") != -1){
lettura=0;
digitalWrite(LEDR, LOW);
Serial.print("Req: ");
Serial.println(req);
estado = "LEDR ON";
Serial.print("Estado: ");
Serial.println(estado);
client.println(estado);
}
if (req.indexOf("SET") != -1){
Serial.print("Req: ");
Serial.println(req);
estado = "SET";
Serial.print("Estado: ");
Serial.println(estado);
client.println(estado);
String thr= req.substring(8);
Value = thr.toInt();
Serial.print("Value: ");
Serial.println(Value);
}
//client.stop();
} // end if (client.available())
if (lettura == 1) {
imu::Quaternion quat = bno.getQuat();
q0= quat.w();
q1=quat.x();
q2= quat.y();
q3=quat.z();
gx = q1 * q3 - q0 * q2;
gy = q0 * q1 + q2 * q3;
gz = q0 * q0 + q3 * q3 -0.5f;
norm = sqrt(gx * gx + gy * gy + gz * gz);
norm = 1.0 / norm;
gx *= norm; gy *= norm; gz *= norm;
phi = acos(gy); phi = phi*radtodeg;
Serial.println(phi);
}
} // end while (client.connected())
} //end (client)
} // end loop()
void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print where to go in a browser:
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
}