maj
This commit is contained in:
parent
adf5bc54b1
commit
1ac49a2ac4
@ -1,76 +0,0 @@
|
||||
/*
|
||||
Arduino leonardo eth v3 and mysql
|
||||
This example demonstrates how to store data in a
|
||||
table in mysql from 4 button connected to pins 2, 3, 4, 5
|
||||
For this, we will create a special database and table for testing.
|
||||
The following are the SQL commands you will need to run in order to setup
|
||||
your database for running this sketch.
|
||||
|
||||
CREATE DATABASE machine;
|
||||
CREATE TABLE machine.state (
|
||||
num integer primary key auto_increment,
|
||||
message char(40),
|
||||
recorded timestamp
|
||||
);
|
||||
|
||||
Here we see one database and a table with three fields; a primary key that
|
||||
is an auto_increment, a string, and a timestamp. This will demonstrate how
|
||||
to save a date and time of when the row was inserted, which can help you
|
||||
determine when data was recorded or updated.
|
||||
|
||||
INSTRUCTIONS FOR USE
|
||||
|
||||
1) Create the database and table as shown above.
|
||||
2) Change the address of the server to the IP address of your MySQL server in my case my IP is 192.186.157.77
|
||||
3) Change the user and password to a valid MySQL user and password in my case it is sa and 156444
|
||||
4) install mysql library in your ide go to sketch > include library > manage library
|
||||
and in the filter your search type mysql then install it
|
||||
5) arduino leonardo use etehrnet2 library so you need to install it in your ide go to sketch > include library > manage library
|
||||
and in the filter your search type ethernet2 then install it
|
||||
6) also you need to modify this file MySQL_Packet.h the original created by Dr.Charles is - include <Ethernet.h>
|
||||
the new is - include <Ethernet2.h> otherwise it will give your error message and not compiled
|
||||
7) Connect a USB cable to your Arduino
|
||||
8) Select the arduino leonardo eth board and port
|
||||
9) Compile and upload the sketch to your Arduino
|
||||
10) connect 4 push button between ground and pins 2, 3, 4, 5 through 10k Ohm resistor
|
||||
11) After the sketch has run for some time , press some push buttons and open a mysql client and issue
|
||||
the command: SELECT * FROM machine.state; to see the data
|
||||
recorded. Note the field values and how the database handles both the
|
||||
auto_increment and timestamp fields for us. You can clear the data with.
|
||||
"DELETE FROM machine.state".
|
||||
|
||||
Note: The MAC on your board in back if not you can put any thing but make sure it is unique in your network .
|
||||
Note your mysql default port address is 3306 but this will conflict with Skype so you can change it to 3307 in both your
|
||||
sketch and your Mysql and make sore this port is open in your server firewall .
|
||||
|
||||
Created by: Samir Mohamad tawfik 28-1-2018
|
||||
samirtwf@gmail.com
|
||||
*/
|
||||
|
||||
#include <Ethernet2.h>
|
||||
#include <MySQL_Connection.h>
|
||||
#include <MySQL_Cursor.h>
|
||||
|
||||
byte mac_addr[] = { 0x90, 0xA2, 0xDA, 0x10, 0xBD, 0x8C };
|
||||
|
||||
IPAddress server_addr(192,168,1,100); // IP of the MySQL *server* here
|
||||
char user[] = "gateway"; // MySQL user login username
|
||||
char password[] = "password"; // MySQL user login password
|
||||
|
||||
EthernetClient client;
|
||||
MySQL_Connection conn((Client *)&client);
|
||||
|
||||
void setup() {
|
||||
EthernetClass(mac_addr);
|
||||
if (conn.connect(server_addr, 3306, user, password)) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
void loop() {
|
||||
delay(1000);
|
||||
char INSERT_SQL[] = "INSERT INTO machine.state (message) VALUES ('machine one on')";
|
||||
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
|
||||
cur_mem->execute(INSERT_SQL);
|
||||
delete cur_mem;
|
||||
delay(1000);
|
||||
}
|
BIN
arduino vers BDD/requette http.docx
Normal file
BIN
arduino vers BDD/requette http.docx
Normal file
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
[{000214A0-0000-0000-C000-000000000046}]
|
||||
Prop3=19,11
|
||||
[InternetShortcut]
|
||||
IDList=
|
||||
URL=https://arduino.stackexchange.com/questions/36663/communication-between-genuino-zero-and-arduino-uno-using-uart
|
5
arduino vers arduino/COM_UART_ARDUINO/connection.txt
Normal file
5
arduino vers arduino/COM_UART_ARDUINO/connection.txt
Normal file
@ -0,0 +1,5 @@
|
||||
Genuino Zero (RX) pin 0 ---------------- Arduino Uno pin 11
|
||||
|
||||
Genuino Zero (TX) pin1 ---------------- Arduino Uno pin 10
|
||||
|
||||
Ground ---------------------------------- Ground
|
47
arduino vers arduino/COM_UART_ARDUINO/receiver/receiver.ino
Normal file
47
arduino vers arduino/COM_UART_ARDUINO/receiver/receiver.ino
Normal file
@ -0,0 +1,47 @@
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial mySerial(10, 11); // RX, TX
|
||||
|
||||
/* Use a variable called byteRead to temporarily store
|
||||
the data coming from the computer */
|
||||
|
||||
byte byteRead;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
mySerial.begin(9600);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
char a[8];
|
||||
/* check if data has been sent from the computer: */
|
||||
if (Serial.available())
|
||||
{
|
||||
/* read the most recent byte */
|
||||
byteRead = Serial.read();
|
||||
//a[0] = atoi(byteRead);
|
||||
//a[1] = atoi(byteRead);
|
||||
Serial.print("rushin\r\n");
|
||||
/*ECHO the value that was read, back to the serial port. */
|
||||
if(byteRead == 0x61)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
Serial.write(byteRead);
|
||||
}
|
||||
}
|
||||
|
||||
if (mySerial.available())
|
||||
{
|
||||
/* read the most recent byte */
|
||||
byteRead = mySerial.read();
|
||||
//a[0] = atoi(byteRead);
|
||||
// a[1] = atoi(byteRead);
|
||||
mySerial.print("rushin\r\n");
|
||||
/*ECHO the value that was read, back to the serial port. */
|
||||
if(byteRead == 0x61)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
mySerial.write(byteRead);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
DigitalReadSerial
|
||||
Reads a digital input on pin 2, prints the result to the serial monitor
|
||||
*/
|
||||
|
||||
// digital pin 2 has a pushbutton attached to it. Give it a name:
|
||||
int pushButton = 7;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
pinMode(pushButton, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int buttonState = digitalRead(pushButton);
|
||||
//if(buttonState == 1)
|
||||
//{
|
||||
Serial.println("a");
|
||||
//}
|
||||
delay(1000);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Software serial multple serial test
|
||||
|
||||
Receives from the hardware serial, sends to software serial.
|
||||
Receives from software serial, sends to hardware serial.
|
||||
|
||||
The circuit:
|
||||
* RX is digital pin 10 (connect to TX of other device)
|
||||
* TX is digital pin 11 (connect to RX of other device)
|
||||
|
||||
*/
|
||||
|
||||
char mavar[7]="bonjour";
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
SoftwareSerial mySerial(10, 11); // RX, TX
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(57600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
//Serial.println("Goodnight moon!");
|
||||
mySerial.begin(4800); // set the data rate for the SoftwareSerial port
|
||||
mySerial.println("je suis la station");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (mySerial.available()) {
|
||||
Serial.write(mavar);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Software serial multple serial test
|
||||
|
||||
Receives from the hardware serial, sends to software serial.
|
||||
Receives from software serial, sends to hardware serial.
|
||||
|
||||
The circuit:
|
||||
* RX is digital pin 10 (connect to TX of other device)
|
||||
* TX is digital pin 11 (connect to RX of other device)
|
||||
|
||||
*/
|
||||
|
||||
char mavar[7];
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
SoftwareSerial mySerial(10, 11); // RX, TX
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(57600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
//Serial.println("Goodnight moon!");
|
||||
mySerial.begin(4800); // set the data rate for the SoftwareSerial port
|
||||
mySerial.println("je suis la passerelle");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (mySerial.available()) {
|
||||
mavar = mySerial.read();
|
||||
}
|
||||
Serial.println(mavar);
|
||||
}
|
||||
|
58
arduino vers web/WebServer/WebServer.ino
Normal file
58
arduino vers web/WebServer/WebServer.ino
Normal file
@ -0,0 +1,58 @@
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
|
||||
// Initialize the Ethernet server library
|
||||
// with the IP address and port you want to use
|
||||
// (port 80 is default for HTTP):
|
||||
EthernetServer server(80);
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
|
||||
// start the Ethernet connection and the server:
|
||||
Ethernet.begin(mac, ip);
|
||||
server.begin();
|
||||
Serial.print("server is at ");
|
||||
Serial.println(Ethernet.localIP());
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// listen for incoming clients
|
||||
EthernetClient client = server.available();
|
||||
if (client) {
|
||||
Serial.println("new client");
|
||||
// an http request ends with a blank line
|
||||
boolean currentLineIsBlank = true;
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so you can send a reply
|
||||
if (c == '\n' && currentLineIsBlank) {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connection: close"); // the connection will be closed after completion of the response
|
||||
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
|
||||
client.println();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
75
arduino vers web/WebServer/WebServer/WebServer.ino
Normal file
75
arduino vers web/WebServer/WebServer/WebServer.ino
Normal file
@ -0,0 +1,75 @@
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
|
||||
// Initialize the Ethernet server library
|
||||
// with the IP address and port you want to use
|
||||
// (port 80 is default for HTTP):
|
||||
EthernetServer server(80);
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
// start the Ethernet connection and the server:
|
||||
Ethernet.begin(mac, ip);
|
||||
server.begin();
|
||||
Serial.print("server is at ");
|
||||
Serial.println(Ethernet.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// listen for incoming clients
|
||||
EthernetClient client = server.available();
|
||||
if (client) {
|
||||
Serial.println("new client");
|
||||
// an http request ends with a blank line
|
||||
boolean currentLineIsBlank = true;
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so you can send a reply
|
||||
if (c == '\n' && currentLineIsBlank) {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connection: close"); // the connection will be closed after completion of the response
|
||||
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
|
||||
client.println();
|
||||
client.println("<!DOCTYPE html><html lang='fr' class=''><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1,user-scalable=no'/>");
|
||||
client.println("<style>div,fieldset,input,select{padding:5px;font-size:1em;}input{width:100%;box-sizing:border-box;}select{width:100%;}textarea{resize:none;width:98%;height:318px;padding:5px;overflow:auto;}body{text-align:center;font-family:verdana;background-color: #bcd5ff;}td{padding:0px;}button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;transition-duration:0.4s;}button:hover{background-color:#006cba;}.p{float:left;text-align:left;}.q{float:right;text-align:right;}</style>");
|
||||
client.println("<title>Passerelle LoRa</title>");
|
||||
client.println("</head>");
|
||||
client.println("<body onload='alea()'><script>function alea() {var x = document.getElementById('demo')x.innerHTML = Math.floor((Math.random() * 10) + 1);}</script>");
|
||||
client.println("<div style='text-align:left;display:inline-block;min-width:340px;'><div style='text-align:center;'><h1>Passerelle LoRa</h1></div>");
|
||||
client.println("<div><h2>[Température actuelle]</h2></div>");
|
||||
client.println("<div><p>Nb d'échant's sent = %, Echec sent : %</p></div><div id='l1' name='l1'></div><table style='width:100%'><tr><button onclick='la('?o=1');'>Informations</button></tr><tr><button onclick='alea()'>rafraichir</button></tr><tr><button onclick='la('?o=1');'>Redémarrer</button></tr></table></div>");
|
||||
client.println("</body></html>");
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
// you're starting a new line
|
||||
currentLineIsBlank = true;
|
||||
} else if (c != '\r') {
|
||||
currentLineIsBlank = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// give the web browser time to receive the data
|
||||
delay(1);
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println("client disconnected");
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" class="">
|
||||
<html lang='fr' class=''>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
|
||||
<meta http-equiv="refresh" content="5" />
|
||||
<meta name='viewport' content='width=device-width,initial-scale=1,user-scalable=no'/>
|
||||
<meta http-equiv='refresh' content='1' />
|
||||
<title>Passerelle LoRa</title>
|
||||
<style>
|
||||
div,fieldset,input,select
|
||||
@ -11,6 +11,7 @@
|
||||
padding:5px;
|
||||
font-size:1em;
|
||||
}
|
||||
|
||||
input
|
||||
{
|
||||
width:100%;
|
||||
@ -18,10 +19,12 @@
|
||||
-webkit-box-sizing:border-box;
|
||||
-moz-box-sizing:border-box;
|
||||
}
|
||||
|
||||
select
|
||||
{
|
||||
width:100%;
|
||||
}
|
||||
|
||||
textarea
|
||||
{
|
||||
resize:none;
|
||||
@ -30,16 +33,19 @@
|
||||
padding:5px;
|
||||
overflow:auto;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
text-align:center;
|
||||
font-family:verdana;
|
||||
background-color: #bcd5ff;
|
||||
background-color: #bcd5ff;
|
||||
}
|
||||
|
||||
td
|
||||
{
|
||||
padding:0px;
|
||||
}
|
||||
|
||||
button
|
||||
{
|
||||
border:0;
|
||||
@ -52,15 +58,18 @@
|
||||
-webkit-transition-duration:0.4s;
|
||||
transition-duration:0.4s;
|
||||
}
|
||||
|
||||
button:hover
|
||||
{
|
||||
background-color:#006cba;
|
||||
}
|
||||
|
||||
.p
|
||||
{
|
||||
float:left;
|
||||
text-align:left;
|
||||
}
|
||||
|
||||
.q
|
||||
{
|
||||
float:right;
|
||||
@ -68,36 +77,34 @@
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body onload='alea()'>
|
||||
<script>
|
||||
function alea() {
|
||||
var x = document.getElementById("demo")
|
||||
x.innerHTML = Math.floor((Math.random() * 10) + 1);
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function alea() {
|
||||
var x = document.getElementById('demo')x.innerHTML = Math.floor((Math.random() * 10) + 1);
|
||||
}
|
||||
</script>
|
||||
<div style='text-align:left;display:inline-block;min-width:340px;'>
|
||||
<div style='text-align:center;'>
|
||||
<h1>Passerelle LoRa</h1>
|
||||
</div>
|
||||
<div>
|
||||
<h2>[Température actuelle]</h2>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
<p>Nombre d'échantillons envoyés = %, Echec d'envoi : %</p>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<h2>[Température actuelle]</h2>
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
Nombre d'échantillons envoyés = %, Echec d'envoi : %
|
||||
</p>
|
||||
</div>
|
||||
<div id='l1' name='l1'></div>
|
||||
<table style='width:100%'>
|
||||
<tr>
|
||||
<button onclick='la("?o=1");'>Informations</button>
|
||||
</tr>
|
||||
<tr>
|
||||
<button onclick='la('?o=1');'>Informations</button>
|
||||
</tr>
|
||||
<tr>
|
||||
<button onclick='alea()'>rafraichir</button>
|
||||
</tr>
|
||||
<tr>
|
||||
<button onclick='la("?o=1");'>Redémarrer</button>
|
||||
</tr>
|
||||
<tr>
|
||||
<button onclick='la('?o=1');'>Redémarrer</button>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
32
lora vers arduino/LoRaReceiver/LoRaReceiver.ino
Normal file
32
lora vers arduino/LoRaReceiver/LoRaReceiver.ino
Normal file
@ -0,0 +1,32 @@
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("LoRa Receiver");
|
||||
|
||||
if (!LoRa.begin(915E6)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// try to parse packet
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize) {
|
||||
// received a packet
|
||||
//Serial.print("Received packet '");
|
||||
|
||||
// read packet
|
||||
while (LoRa.available()) {
|
||||
Serial.print((char)LoRa.read());
|
||||
}
|
||||
|
||||
// print RSSI of packet
|
||||
//Serial.print("' with RSS
|
||||
//Serial.println(LoRa.packetRssi());
|
||||
}
|
||||
}
|
33
lora vers arduino/LoRaSender/LoRaSender.ino
Normal file
33
lora vers arduino/LoRaSender/LoRaSender.ino
Normal file
@ -0,0 +1,33 @@
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
int counter = 0;
|
||||
char mes[] = "message :";
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("LoRa Sender");
|
||||
|
||||
if (!LoRa.begin(915E6)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("paquet envoyé : ");
|
||||
Serial.println(counter);
|
||||
|
||||
// send packet
|
||||
LoRa.beginPacket();
|
||||
LoRa.print("message : ");
|
||||
LoRa.print(counter);
|
||||
LoRa.print("\n");
|
||||
LoRa.endPacket();
|
||||
|
||||
counter++;
|
||||
|
||||
delay(1000);
|
||||
}
|
BIN
lora vers arduino/LoRa_Shield_Pin_Mapping.png
Normal file
BIN
lora vers arduino/LoRa_Shield_Pin_Mapping.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 499 KiB |
Loading…
Reference in New Issue
Block a user