Hi guys, i'm a new user of arduino so i'm not very skilled to use it.
My hardware is:
-Arduino Uno
-Wireless Sd Shield
-Wirelezz module RN-XV 171
I have installed the WiFly library and i have created a mock server with postman with a easly get request that return "ok" massage.
I use a examples skecth from the WiFly library.
The code is:
#include <WiFlyHQ.h>
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(8,9);
//#include <AltSoftSerial.h>
//AltSoftSerial wifiSerial(8,9);
WiFly wifly;
/* Change these to match your WiFi network */
const char mySSID[] = "******";
const char myPassword[] = "******";
const char site[] = "http://*******.mock.pstmn.io";
void terminal();
void setup()
{
char buf[32];
Serial.begin(9600);
Serial.println("Starting");
Serial.print("Free memory: ");
Serial.println(wifly.getFreeMemory(),DEC);
wifiSerial.begin(9600);
if (!wifly.begin(&wifiSerial, &Serial)) {
Serial.println("Failed to start wifly");
terminal();
}
/* Join wifi network if not already associated */
if (!wifly.isAssociated()) {
/* Setup the WiFly to connect to a wifi network */
Serial.println("Joining network");
wifly.setSSID(mySSID);
wifly.setPassphrase(myPassword);
wifly.enableDHCP();
if (wifly.join()) {
Serial.println("Joined wifi network");
} else {
Serial.println("Failed to join wifi network");
terminal();
}
} else {
Serial.println("Already joined network");
}
//terminal();
Serial.print("MAC: ");
Serial.println(wifly.getMAC(buf, sizeof(buf)));
Serial.print("IP: ");
Serial.println(wifly.getIP(buf, sizeof(buf)));
Serial.print("Netmask: ");
Serial.println(wifly.getNetmask(buf, sizeof(buf)));
Serial.print("Gateway: ");
Serial.println(wifly.getGateway(buf, sizeof(buf)));
wifly.setDeviceID("Wifly-WebClient");
Serial.print("DeviceID: ");
Serial.println(wifly.getDeviceID(buf, sizeof(buf)));
if (wifly.isConnected()) {
Serial.println("Old connection active. Closing");
wifly.close();
}
if (wifly.open(site, 80)) {
Serial.print("Connected to ");
Serial.println(site);
/* Send the request */
wifly.println("GET /test HTTP/1.0 ");
wifly.println();
} else {
Serial.println("Failed to connect");
}
}
void loop()
{
if (wifly.available() > 0) {
char ch = wifly.read();
Serial.write(ch);
if (ch == '\n') {
/* add a carriage return */
Serial.write('\r');
}
}
if (Serial.available() > 0) {
wifly.write(Serial.read());
}
}
/* Connect the WiFly serial to the serial monitor. */
void terminal()
{
while (1) {
if (wifly.available() > 0) {
Serial.write(wifly.read());
}
if (Serial.available() > 0) {
wifly.write(Serial.read());
}
}
}
When i run this code with HTTP/1.0 i have this error
16:19:04.509 -> open http://a************************5f.mock.pstmn.io 80
16:19:04.741 -> Connected to http://******************5f.mock.pstmn.io
16:19:04.907 -> HTTP/1.1 401 Unauthorized
16:19:04.940 ->
Access-Control-Allow-Origin: *
16:19:04.974 ->
Content-Type: application/json; charset=utf-8
16:19:05.040 ->
Date: Tue, 17 Sep 2019 14:19:05 GMT
16:19:05.073 ->
ETag: W/"63-NBrQ********************mc"
16:19:05.107 ->
Server: nginx
16:19:05.140 ->
Vary: Accept-Encoding
16:19:05.174 ->
x-srv-span: v=1;s=f1********23b
16:19:05.208 ->
x-srv-trace: v=1;t=2af********6
16:19:05.242 ->
Content-Length: 99
16:19:05.275 ->
Connection: Close
16:19:05.275 ->
16:19:05.275 ->
{"error":{"name":"invalidCredentialsError","message":"Unable to authenticate using access token."}}
Instead if i set HTTP/1.1 i have this other error
18:15:59.170 -> DeviceID: Wifly-WebClient
18:16:00.307 -> open http://a*******************************5f.mock.pstmn.io 80
18:16:00.507 -> Connected to http://a**************************f.mock.pstmn.io
18:16:00.673 -> HTTP/1.1 400 BAD_REQUEST
18:16:00.707 ->
Content-Length: 0
18:16:00.707 ->
Connection: Close
Please help me, thanks you guys.