The data collector is a lightweight microservice application that sends metadata, collected from a system, such as an IoT network, distributed system, data center, etc.
https://www.raspberrypi.org/downloads/raspbian/[Download^] the Raspbian disc image - Choose Raspbian Lite
[NOTE]
.Why Raspbian Lite?
====
Because it is a lightweight version of the Raspbian and it doesn’t have a graphical user interface installed.
This means that it doesn’t have any unnecessary software installed that we don’t need for our projects, so this makes it the perfect solution for future automation projects.
====
==== Step 2: Unzip the file
- Windows users, you’ll want 7-Zip.
- Linux users will use the appropriately named Unzip.
==== Step 3: Write the disc image to your microSD card
Next, pop your microSD card into your computer and write the disc image to it. You’ll need a specific program to do this:
- Windows users, your answer is https://sourceforge.net/projects/win32diskimager/[Win32 Disk Imager^].
- Linux people, https://www.balena.io/etcher/[Etcher – which also works on Windows – is what the Raspberry Pi Foundation recommends^]
The process of actually writing the image will be slightly different across these programs, but it’s pretty self-explanatory no matter what you’re using.
- Each of these programs will have you select the destination (make sure you’ve picked your microSD card!) and the disc image (the unzipped Raspbian file).
- Choose, double-check, and then hit the button to write.
$serial->sendMessage("Hello from my PHP script, say hi back!");
$serial->deviceClose();
echo "I've sended a message! \n\r";
----
==== NodeJS
[NOTE]
====
Read the writing carefully on your Raspberry Pi circuit board to confirm it indicates something like “Raspberry Pi 4 Model B” or “Raspberry Pi 2 Model B”. If in doubt, run the following command in the terminal:
$ uname -m
If the result returned starts with **“armv6”**, you are running a Raspberry Pi based on the older ARMv6 chipset and the next Node.js installation step **will not work**; otherwise, you are ready for the next step.
TIP: You can find more information https://git.swarmlab.io:3000/zeus/iot-swarm-example/src/branch/master[here^] and http://docs.swarmlab.io/SwarmLab-HowTos/index-lab.adoc.html#_iot_swarm_implementation[here^]
== How to communicate Arduino2Raspberry
Blinking example (*)
=== Arduino code
[source,c]
----
/*
* serial_usb_simple_arduino - For communicating over USB serial. Send it a '1' (character one)
* and it will make the builtin LED start blinking every one second. Send it a '0'
* (character zero) and it will make it stop blinking.
*
* Each time it receives one of the commands, it sends back an 'A' for acknowledge.
* But send it a commmand it doesn't recognize and it sends back an 'E' for error.
*/
bool blinking = false;
bool led_on = false;
int target_time;
void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
char c;
if (Serial.available() > 0) {
c = Serial.read();
switch (c) {
case '0':
// stop blinking
blinking = false;
if (led_on) {
digitalWrite(LED_BUILTIN, LOW);
}
Serial.write("A", 1);
break;
case '1':
// start blinking
if (blinking == false) {
blinking = true;
digitalWrite(LED_BUILTIN, HIGH);
led_on = true;
target_time = millis() + 100; // turn off in 1 tenth of a second (100 milliseconds)
}
Serial.write("A", 1);
break;
default:
Serial.write("E", 1);
break;
}
} else if (blinking) {
if (millis() >= target_time) {
if (led_on) {
digitalWrite(LED_BUILTIN, LOW);
led_on = false;
target_time = millis() + 100; // turn on in 1 tenth of a second (100 milliseconds)
} else {
digitalWrite(LED_BUILTIN, HIGH);
led_on = true;
target_time = millis() + 100; // turn off in 1 tenth of a second (100 milliseconds)
}
}
}
}
----
=== Raspberry Pi C language
[source,c]
----
/*
* serial_usb_simple - Demo that communicates over USB using serial I/O
* from a Raspberry Pi to an Arduino.
*
* To show that it work, this writes a '1' to the Arduino which then
* blinks the builtin LED on and off. The Arduino also sends back an 'A'
* to acknowledge that it got the message. This does a read() to get
* the 'A', demonstrating that reading also works. Two seconds later,
* this writes a '0' to the Arduino which then stops the blinking.
* The Arduino again sends back an 'A' to acknowledge that it got the
* message and this reads the 'A'.
*
* This was tested between a Raspberry Pi 3B (running Raspbian) and
* an Arduino Mega 2560 and also between an NVIDIA Jetson TX1 (running