I am trying to encrypt/decrypt 128 byte of data [using AES128] in an arduino UNO.
#include <AESLib.h>
void setup(){
Serial.begin(9600);
}
void loop(){
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
char data[] = "ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF123 4567890ABCDEF12345 67890ABCDEF1234567890ABCDEF1234567890";//128 byte
aes128_enc_single(key, data);
Serial.println(data);
aes128_dec_single(key, data);
Serial.println(data);
delay(15000);
}
avr-gcc: error: unrecognized command line option ‘-assembler-with-cpp’
This is the error I am getting. Should I update gcc?
Related
I have XBEE S2C's. I have 2 Arduino MEGA. One part of them will be receiver and other is transmitter. I communicated and configured XBee's.I tested it That's okey. But the problem is I can't send float value like longtitude= 38,45682469 latitude= 85,24698534. When I try to do this I receive only latitude = 85
longtitude = 38. How can I change my code to receive healthy data.
TRANSMITTER
#include "SoftwareSerial.h"
#include <TinyGPS.h>
float lat,lon;
TinyGPS gps;
SoftwareSerial XBee(10, 11);
void setup(){
Serial.begin(9600);
XBee.begin(9600);
Serial.println("The GPS Received Signal:");
Serial3.begin(9600);
}
void loop(){
while(Serial3.available()){
if(gps.encode(Serial3.read()))
{
gps.f_get_position(&lat,&lon);
Serial.print("Position: ");
Serial.print("Latitude: ");
Serial.print(lat,8);
Serial.print(",");
Serial.print("Longitude: ");
Serial.println(lon,8);
}
}
XBee.write("l");
XBee.write(lat);
delay(100);
XBee.write("k");
XBee.write(lon);
delay(100);
}
Most robust is to convert float to string, send it over serial, and let the receiver convert back to float.
Sender:
XBee.write(String(lat,5)); // keep 5 decimals
Receiver:
String inString = "";
while (Serial.available()) {
char c = Serial.read();
inString += c;
}
float myFloat = inString.toFloat();
Further reading:
https://www.arduino.cc/en/Tutorial/StringToFloatExample
https://www.arduino.cc/en/Reference.StringConstructor
Hello I am programming a bluetooth connection from Android Studio to Arduino. The connection works and it sends the String. I only get something like this tho on my Arduino (x?xx?xx??xxx?xxx?x) the questionmarks are the other way the string I send is on
This is my code:
#include <SoftwareSerial.h>
#define rxPort 11
#define txPort 10
char btData;
String string;
SoftwareSerial btSerial(rxPort, txPort);
void setup(){
Serial.begin(9600);
btSerial.begin(38400);
Serial.println("bluetooth available");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
if(btSerial.available()>0){
string = "";
}
while(btSerial.available()>0){
btData = (byte)btSerial.read();
if(btData==":"){
break;
}else{
string += btData;
}
delay(1);
Serial.println(string);
}
if(string == "on"){
digitalWrite(LED_BUILTIN,HIGH);
}
}
why do you cast the read to byte??
char it is :)
it should work with 9600 BAUD rate as well
example from my project (I didn't build String though - used single char as command)
SoftwareSerial blue(3, 5); // BlueTooth RX, TX;
void BluetoothSetup()
{
blue.begin(9600);
blue.print("AT+NAMEKuku"); // give it a name
delay(2000);
Serial.println("got BT");
}
void setup() {
....
BluetoothSetup();
....
}
void loop() {
if (blue.available()) {
char r = blue.read();
ProcessRemoteCommand(r);
}
}
I am connecting a sensor to android device through arduino. I need to encrypt my sensor data and then send it to android device. But when I include aes128_enc_single(key, temp), It gives an error and said "aes128_enc_single' was not declared in this scope "
What should I do for this?
I have included AESLib.h library
My sample code is
#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#include <AESLib.h>
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
SoftwareSerial blue(2,3);
int i = 0;
float temp = 0;
void setup() {
Serial.begin(9600);
blue.begin(9600);
}
void loop() {
i = analogRead(A0);
temp = (i/1024.0)*500;
Serial.println(temp);
aes128_enc_single(key, temp);
Serial.print("encrypted:");
Serial.println(temp);
blue.print("Encrypted Temperature: ");
blue.println(temp);
delay(1000);
}
I have followed the steps outlined in the following link to install and run the Mosquitto broker on my laptop.
https://sivatechworld.wordpress.com/2015/06/11/step-by-step-installing-and-configuring-mosquitto-with-windows-7/
I have tested the publishing and subscription events using command line i.e, the mosquitto_pub and mosquitto_sub commands and they worked fine!
I want to publish to this broker running on my laptop (listening to port 1883 - confirmed using the netstat-an command) using an Arduino which is using the functions from "PubSubClient" library.
For the server's IP address in the Arduino Publish sketch, I have given the IP address of my laptop itself which it gets when it connects to my home network. Following is the publisher code:
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#define CLIENTID "Arsen"
const char topic[] = "tem";
#define POLLINTERVAL 120000
void callback(char* topic, byte* payload, unsigned int length){
//Do nothing as we are publishing ONLY.
}
byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED} ;
IPAddress server(192, 168, 0, 10);
EthernetClient ethClient;
PubSubClient arduinoClient(server,1883, callback, ethClient) ;
unsigned long boardTime = 0 ;
float sensedTemperature = 0;
char charTemp [6];
int connRC = 0;
void setup(void) {
Serial.begin(9600);
//Connect to the MQTT server - test.mosquitto.org
beginConnection() ;
}
//Initialise MQTT connection
void beginConnection() {
Serial.begin(9600);
Ethernet.begin(mac) ; //using the address assigned through DHCP
do{
int connRC = arduinoClient.connect(CLIENTID);
}while(connRC==1);
Serial.println("We are connected finally");
delay(5000);
Serial.println(arduinoClient.state());
}
void loop(void) {
boardTime = millis();
if ((boardTime % POLLINTERVAL) == 0) {
getTemp();
dtostrf(sensedTemperature,5,2,charTemp);
boolean rec = arduinoClient.publish(topic, charTemp);
Serial.println(rec);
Serial.println("Successfully published");
}
arduinoClient.loop();
}
void getTemp() {
// Send the command to get temperatures
delay(100);
sensedTemperature = analogRead(2); //temperature sensor at analog pin 2 on Arduino.
Serial.println(sensedTemperature);
delay(150);
}
The subscriber code is:
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <EthernetServer.h>
#include <EthernetClient.h>
#include <Dns.h>
#include <Dhcp.h>
#include <SPI.h>
#include <PubSubClient.h>
#define PIN 13
//MQTT Definition
#define CLIENTID "Aract"
#define TOPICNAME "tem"
byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED} ;
IPAddress server(192,168,0,5); // Mosquitto Server
int connRC = 0;
//Handle message from mosquitto and set LEDs
void callback(char* topic, byte* payload, unsigned int length) {
int i=0; char buffer [length];
for(i=0;i<length;i++) {
buffer [i] = char((payload[i]));
}
String payLoadData = buffer;
Serial.println(payLoadData);
setled(payLoadData);
}
//Our MQTT client
EthernetClient ethclient;
PubSubClient arduinoClient(server, 1883, callback, ethclient) ;
void setup() {
//Connect to the MQTT server - test.mosquitto.org
beginConnection() ;
}
//Initialise MQTT connection
void beginConnection() {
Serial.begin(9600);
Ethernet.begin(mac) ;
do{
connRC = arduinoClient.connect(CLIENTID) ;
delay(2000);
}while(connRC==1);
delay(3000);
Serial.println(arduinoClient.state());
if (connRC==1) {
boolean rec = arduinoClient.subscribe(TOPICNAME) ;
Serial.println(rec);
Serial.println("Successfully Subscribed");
} else {
Serial.println("connRC") ;
}
}
void loop()
{
arduinoClient.loop() ;
}
void setled(String s)
{
int temperature;
temperature = s.toInt();
Serial.println(temperature);
if (temperature >= 200){
digitalWrite(PIN, HIGH);
}
else{
digitalWrite(PIN, LOW);
}
}
The Ethernet shield is working well as it successfully executed the example programs. The state function returns "zero" which implies that the board is connecting to the network. However, the publish command returns a boolean value "rec" which is giving false. I want to know as to why this process is being unsuccessful all the time?
The verbose option (-v) along with Mosquitto on command line throws up an unknown error instead of showing the logged details. How to overcome this problem or what exactly is wrong in my technique?
I had faced the same problem and I got the solution as this...
Just go to the services running in your PC and stop the mosquitto-broker, now open the cmd and change the directory to the place where mosuitto files were located (in my case it is "cd C:\Program Files (x86)\mosquitto") and then enter this command mosquitto -v, now just left that window like that (If u closed then it won't work)...
It really worked and the reason why its not working in before case is, when we started moquitto-broker service then its not opening ports for IPv4 and here is the reference "Mosquitto Error"
iam using itead sim908 Gsm/Gps/Gprs Module with Arduino Uno, iam trying to send Gps coordinates by Sms message and by gprs to internet server, but cant run it both same time, Although it's work separately.
when i try to send GPS coordinates via SMS message and send data via gprs to server same time i have this error :
ERROR: SIM900 doesn't answer. Check power and serial pins in GSM.cpp
this is my code, any one have a solution ?
#include "SIM900.h"
#include
#include "inetGSM.h"
#include "sms.h"
//#include "call.h"
#include "gps.h"
char smsbuffer2[150];
char id[]="12";
char httpbuffer[160];
InetGSM inet;
//CallGSM call;
SMSGSM sms;
GPSGSM gps;
char msg[50];
int numdata;
char lon[15];
char lat[15];
char alt[15];
char time[20];
char vel[15];
char msg1[5];
char msg2[5];
char Mobile[]="0595285486";
char stat;
char inSerial[50];
int i=0;
boolean started=false;
void setup(){
get_gps();
delay(1000);
send_server();
delay(1000);
send_sms();
}
void loop(){
}
void get_gps(){
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(9600)) {
Serial.println("\nstatus=READY");
started=true;
gsm.forceON();
} else Serial.println("\nstatus=IDLE");
if(started) {
//GPS attach
if (gps.attachGPS())
Serial.println("status=GPSREADY");
else Serial.println("status=ERROR");
delay(20000); //Time for fixing
stat=gps.getStat();
if(stat==1)
Serial.println("NOT FIXED");
else if(stat==0)
Serial.println("GPS OFF");
else if(stat==2)
Serial.println("2D FIXED");
else if(stat==3)
Serial.println("3D FIXED");
delay(5000);
//Get data from GPS
gps.getPar(lon,lat,alt,time,vel);
Serial.println(lon);
Serial.println(lat);
Serial.println(alt);
Serial.println(time);
Serial.println(vel);
convert2Degrees(lat);
convert2Degrees(lon);
}
}
void send_server(){
if (gsm.begin(9600)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started) {
//GPRS attach, put in order APN, username and password.
//If no needed auth let them blank.
if (inet.attachGPRS("internet", "", ""))
Serial.println("status=ATTACHED");
else Serial.println("status=ERROR");
delay(1000);
//Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
delay(5000);
//Read until serial buffer is empty.
gsm.WhileSimpleRead();
//TCP Client GET, send a GET request to the server and
//save the reply.
/*
httpbuffer[0]='\0';
strcat(httpbuffer,"/GetData.aspx?lat=");
strcat(httpbuffer,lat);
strcat(httpbuffer,"&&lon=");
strcat(httpbuffer,lon);
strcat(httpbuffer,"&&id");
strcat(httpbuffer,id);
Serial.println(httpbuffer);
*/
numdata=inet.httpPOST("qou.azurewebsites.net", 80,"httpbuffer", msg, msg,12);
//Print the results.
Serial.println("\nNumber of data received:");
Serial.println(numdata);
Serial.println("\nData received:");
Serial.println(msg);
}
}
void send_sms(){
if (gsm.begin(9600)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started){
smsbuffer2[0]='\0';
strcat(smsbuffer2,"Vehicle Accident Occurs to Vehicle which Have ");
strcat(smsbuffer2,"ID number");
strcat(smsbuffer2,id);
strcat(smsbuffer2,"in Location :");
strcat(smsbuffer2,lat);
strcat(smsbuffer2,lon);
strcat(smsbuffer2,"Owner Name:Ayman Abd Albasit Sadq Daqah");
strcat(smsbuffer2,"Mobile :");
strcat(smsbuffer2,Mobile);
if (sms.SendSMS(Mobile, "smsbuffer2"))
Serial.println("\nSMS sent OK");
}
}