Back to overview 4.4

Using HTTP

For most small or private applications the easiest way for devices to communicate is HTTP. This way you can easily access them with a browser using your computer or even your smartphone. To work with HTTP we have the ConnectinoAjax library.

It is always essential to include the ConnectinoAjax-module, to initialize an instance of the module and to setup the StxSerial. The software automatically executes the start()-function at the start of the ATmega. You can use the loop() to continuously execute functions or test parameters.

Enable and configure module

Download example: ConnectinoHttp.ino

	#include <ConnectinoAjax.h> // include the ConnectinoAjax-library

	// initialize the Ajax-module on the UART
	ConnectinoMqtt ajax = ConnectinoAjax(StxSerial);

	void setup()
		// enable the uart and add communication via ajax-module

	char ajaxCmd[127];
	uint16_t cmdLen;

	void loop()
			ajax.getData(ajaxCmd, cmdLen); // get the data and get its length
			if(strcmp(ajaxCmd, "Marco")) // if received message was "Marco"
				ajax.respond("Polo"); // respond with "Polo"