The HTTP_Client Class extends the Arduino core class ‘Client’ with http-POST and -GET request functions. It is the base class for the following derived classes:
CANIP_Client
– for TCP traffic over CAN bus (all dice)EthernetHTTPClient
– for ethernet based TCP connections (dice-ETH)GSMHTTPClient
– GSM TCP traffic to the internet (e.g. dice-IoT)WiFiHTTPClient
– WiFi based TCP connections (e.g. dice-WiFi)
Now any of the clients above provide functions that facilitate http requests:httpGET()
/ httpGETSSL()
httpPOSTStart()
/ httpPOSTCreateBoundary
/ httpPOSTEnd()
connect() / connectSLL()
The HTTP_Client Class itself is a descendant from:
- the Arduino core class ‘Client’ and its functions such as connect(), write(), read(), stop() and available() etc.
- and the corresponding technology classes
so that it can be used just like those as well.
To use this class
Depending on the technology (GSM, WiFi etc.) include one (or more) of the following HTTP_Client – classes:
#include "CANIP.h" /* use this for TCP via CAN */ #include "DICE_Ethernet.h" /* use this for dice-ETH */ #include "DICENB" /* for dice-IoT*/ #include "WiFiNINA.h" /*or include this for dice-WiFi */
Now in the application create a corresponding HTTP_Client object:
CANIP_Client myClient(&MCAN0, &BOOTLOADER_SETTING);
EthernetHTTPClient myClient;
GSMHTTPClient myClient;
WiFiHTTPClient myClient;
GET-Example (WiFi)
#include <WiFiNINA.h>
char ssid[] = "mySSID";
char pass[] = "myPass";
WiFiHTTPClient myClient;
void setup()
{
while(!Serial);
Serial.println("WiFiHTTPClient Example");
while(WiFi.begin(ssid, pass) != WL_CONNECTED)
delay(10000);
Serial.println("Connected to WiFi");
int iResponse = myClient.httpGET("di-ce.de",
"/downloads/dice-ascii-logo.txt");
if( iResponse <= 0)
Serial.println("Error: "+String(iResponse));
else
{
Serial.println("Connected to Server");
while(myClient.connected() || myClient.available())
{
while(myClient.available() > 0)
{
if( Serial.availableForWrite())
{
char c = myClient.read();
Serial.write(c);
}
yield();
}
yield();
}
}
Serial.println("\n- disconnected from server -");
myClient.stop();
}
void loop()
{ }
HTTP_Client Class notes:
SSL / TLS functionality is not available on the dice-ETH and the CAN2SER – CANIP provider.
Further information
Client interface
CANIP
WiFiNINA
DICENB / DICEGSM – Library
DICE_Ethernet
writeFromClient()
readToClient()
HTTP_Client-Class
Additional Methods: