Page tree
Skip to end of metadata
Go to start of metadata

The Archer Cloud provides you an easy and fast way to visualize and even control your Arduino projects over the internet with individual UI graphics based on SVG. 

The Arduino client library is designed to give you a comfortable way in making Archer Cloud panels usable for your Arduino projects. If you don't have enough knowledge about the concepts of the Archer platform, please read the basic instructions first. Archer Documentation

You can view and download the source code form https://github.com/byteAgenten/ArduinoArcherPanelClient.

Example Project

Please have a look at our elevator example project that simulates an elevator control by using Arduino and an Archer Cloud panel.

Dependencies

All code snippets below are based on the usage of the following libraries. The Arduino Client library has no direct dependencies to other Arduino libraries.

LibraryDescriptionSource
WiFi101Connecting to wireless lanhttps://github.com/arduino-libraries/WiFi101
WebSocketClientEstablish websocket connectionshttps://github.com/arduino-libraries/ArduinoHttpClient

Other third party libraries

You should also be able to use other third party libraries, for connecting to the internet and establish websocket connections. But we only tried it with the two above.

Websocket access

Please mind that the used WebSocketClient library is not able to establish secured websocket connections. As of today we have not found any third party websocket library that is able to use secured websocket connections. Therefore we provide an additional websocket endpoint that is not encrypted by SSL. It is your own risk to use this endpoint! For a more secure setup you could use a proxy within your local network. The proxy can then forward the unsecured websocket connection via a secured connection.

Available archer panel websocket endpoints:

EndpointURL
Default (secure)
wss://cloud.archer.graphics:80/panels/websocket/client
For Arduino ((warning) unsecure!)
ws://wsbridge.archer.graphics:80

 

Required dependencies

Library include
#include <WiFi101.h>
#include <WebSocketClient.h>
#include <ArduinoArcherPanelClient.h>

Connect to the Archer Cloud

Send authentication
//the url to the websocket endpoint
const char WS_URL[] = "wsbridge.archer.graphics"; 
 
//the port to the websocket endpoint
const int WS_PORT = 80; 
 
const char SSID[] = "---YOUR_WLAN_NAME---";
const char WAP[] = "---YOUR_WLAN_PASSWORD---";
 
//Connect to the internet via the wlan and start a websocket connection
WiFiClient wifi;
WebSocketClient wsClient(wifi, WS_URL, WS_PORT);

int wifiStatus = WL_IDLE_STATUS;
while ( wifiStatus != WL_CONNECTED) {
    
	// Connect to WPA/WPA2 network:
    wifiStatus = WiFi.begin(SSID, WAP);
}
Serial.println("Network connected successfully!");
 
wsClient.begin();

Generic function for sending commands

Send a websocket message
void sendCommand(PanelCommand& command) {

	//serialize the command to json
 	String json = command.toJson();
 
	//start websocket message
  	wsClient.beginMessage(TYPE_TEXT);
 
	//send the json via websocket
  	wsClient.print(json);
 
	//end websocket message
  	wsClient.endMessage();
}

Authenticate for Archer Cloud panel

For sending variable values to the Archer Cloud panel and receiving events from the panel you need to authenticate. Please read Archer Panels for more information.

Send authentication
const char ACCESS_KEY_ID[] = "1234567";
const char ACCESS_KEY[] = "---some-uuid---";
 
//create an authentication command object instance
AuthenticateCommand command(ACCESS_KEY_ID, ACCESS_KEY);
sendCommand(command);

Generic function for reading events

Read a websocket message
void readWS() {

	//check for available message on websocket
  	if (wsClient.parseMessage() > 0) {
    
		//read json message from websocket
    	String json = wsClient.readString();
    
    	// deserialize json to panel event
    	PanelEvent* event = PanelEvent::jsonToEvent(json);
 
		// do something with the event
    	handlePanelEvent(event);
  	}
}

Handle events according to type

Handle panel events
void handlePanelEvent(PanelEvent* event) {

    if( event->isTypeOf(AuthenticateResponseEvent::type)) {
      
      handleAuthenticationEvent((AuthenticateResponseEvent*)event);
      
    } else if( event->isTypeOf(ElementClickEvent::type)) {

      handleElementClickEvent((ElementClickEvent*)event);         
    }
}

Handle authentication response

Once you have sent an authentication command you will receive an authentication response that contains information whether the authentication was successful.

Read authentication response
void handleAuthenticationEvent(AuthenticateResponseEvent* event) {

	// check if authentication was successful
  	if( event->isAuthenticated() ) {
        
   		Serial.println("Authentication successful!");
  	}
}

Send variable value

Send variable value
const char PANEL_ID[] = "---YOUR_PANEL_ID---";
 
//create a setVariable command object instance
String variableName = String("my-variable-name");
String variableValue = String("my-variable-value");
SetVariableCommand command(PANEL_ID, variableName.c_str(), variableValue.c_str(), variableValue.c_str());
sendCommand(command);

Observing Archer Cloud panels

If you want to receive events from an Archer Cloud panel, you first have to send an observe panel command. The command has to contain a list of IDs from all panels you want to get events from.

Send variable value
//create a character pointer array containing the Archer Cloud panel ids
const char* panelIds[1];
panelIds[0] = "---A_PANEL_ID---";
 
//create an observePanelsCommand object instance
ObservePanelsCommand command(panelIds);
sendCommand(command)

Handling click events from the Archer Cloud panel

If you receive an Archer Cloud panel click event, you can use the elementId property of the event to handle specific to the clicked element.

Send variable value
void handleElementClickEvent(ElementClickEvent* event) {

	String panelId = event->getPanelId();
 	String elementId = event->getElementId();
   	// do something according to the click
}
  • No labels