Go Down

Topic: Arduino mkr1000 does not Serial print upon GET using aRest library (Read 2285 times) previous topic - next topic

John41234

I'm trying to create a REST server on an arduino mkr1000. upon searching google i came upon the aRest library which handles most of the stuff i need.


aRest library documentation

So i created a sample sketch based on the guides. Here is the code:



   #include < SPI.h >
   #include < WiFi101.h >
   #include < aREST.h >
   
   aREST rest = aREST();
   
   int status = WL_IDLE_STATUS;
   WiFiServer restServer(80);
   
   char ssid[] = "user";  // not actual username
   char pass[] = "pass";  // not actual password
   
   
   int clapMode(String data){
     Serial.println("Request Recieved: " + data);
   }
   
   
   void setup() {
   
    Serial.begin(115200);
   
    rest.set_id("000");
    rest.set_name("MKR1000");
    rest.function("test",clapMode);
     
    while ( status != WL_CONNECTED) {
      Serial.print("Attempting to connect to SSID: ");
      Serial.println(ssid);
      // Connect to WPA/WPA2 network. Change this line if using open or WEP
   network:
      status = WiFi.begin(ssid, pass);
      // wait 10 seconds for connection:
      delay(10000);
    }
   
    Serial.println();
   
    // you're connected now, so print out the status:
    printWifiStatus();
   
    // Start server
    restServer.begin();
    Serial.println(F("Listening for connections..."));
   
   }
   
   void loop() {
     WiFiClient client = restServer.available();
       if (!client) {
       return;
     }
     while(!client.available()){
       delay(1);
     }
     rest.handle(client);
   }
   
   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);
   
     IPAddress subnet = WiFi.subnetMask();
     Serial.print("Netmask: ");
     Serial.println(subnet);
   
     IPAddress gateway = WiFi.gatewayIP();
     Serial.print("Gateway: ");
     Serial.println(gateway);
   
     // print the received signal strength:
     long rssi = WiFi.RSSI();
     Serial.print("signal strength (RSSI):");
     Serial.print(rssi);
     Serial.println(" dBm");
   }

The code works mostly. Upon using POSTMAN to perform a GET the arduino is able to give the appropriate response.

Now for the part that is not working is the endpoint i just have created using this code

   rest.function("test",clapMode);

upon performing a GET in postman, the arduino is able to give a response, but it should perform this code

   int clapMode(String data){
     Serial.println("Request Recieved: " + data);
   }

but on my serial Monitor i am not getting anything.







Also i could not find on how to tailor the response of the arduino from the request. How do i it ?


Thank you very much


John41234

My bad. I named the endpoint to "test" so it should be 192.168.54.118/test

Go Up