How to setup seeeduino with lorawan? - arduino

I'm trying to implement communication between a seeeduino lorawan and the things network. The gateway is setup, however I've been unable to load the correct lorawan information onto the seeeduino.
I've been following the tutorial from their website: http://wiki.seeedstudio.com/Seeeduino_LoRAWAN/
The seeeduino does connect and I can upload code onto the seeeduino to read and print sensor data via serial, so the IDE settings, like board should be correct.
Problem 1: library LoRaWan.h is not known
Problem 2: When using a different Beelan Lorawan library, the library import works, but commands such as lora.getversion, lora.setid, etc. cause an error, because they don't exist.
So the main question really is, how to I let the seeeduino know, which AppSKey, DevEUI, AppEUI, etc. it should use?
#include <LoRaWan.h>
void setup(void)
{
Serial.begin(115200);
lora.init();
memset(buffer, 0, 256);
lora.getVersion(buffer, 256, 1);
SerialUprint(buffer);
memset(buffer, 0, 256);
lora.getId(buffer, 256, 1);
Serial.print(buffer);
// void setId(char *DevAddr, char *DevEUI, char *AppEUI);
lora.setId(NULL, "12409E2345695432", "70B3D57EF0006593");
// setKey(char *NwkSKey, char *AppSKey, char *AppKey);
lora.setKey(NULL, NULL, "47BDA77B6D7B4DDA7DC182E54295FE4E");
}
void loop(void)
{
}

The problem was with the newer 1.5.6 board version. Reverting to board version 1.3 of Seeed SAMD Boards installed the missing LoRaWaN library and allowed for a successfull setup of the lorawan components.

Related

Can't read Modbus holding register because ModbusMaster for arduino is lack of documentation

The Problem:
Hi, First of all, i am no expert at C++.
I seem can't find any of the guide(or documentation) of modbusMaster especially for this particular library. Which explains all the class method uses.
I use this library because it supports stream class. not like official library or others. Therefore, i can use softwareSerial to add more serial for rs485.
I am using Arduino pro mini, that's why i need software serial. And this Max485 module:
I am very sure everything is connected properly, thus my aim is to read coil from a Chinese brand ultrasonic level meter which the guide says:
Here's the program what i am trying to do:
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
/*!
We're using a MAX485-compatible RS485 Transceiver.
Rx/Tx is hooked up to the hardware serial port at 'Serial'.
The Data Enable and Receiver Enable pins are hooked up as follows:
*/
#define MAX485_DE 9
#define MAX485_RE_NEG 8
//for software serial
#define RO_RX 7
#define DI_TX 6
// instantiate ModbusMaster object
ModbusMaster node;
// RX, TX on softser
SoftwareSerial mySerial(RO_RX, DI_TX);
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
// Init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// for serial monitoring on PC
Serial.begin(115200);
// Modbus communication runs at 9600 baud
mySerial.begin(9600);
// Modbus slave ID 1 and pass the software serial
node.begin(1, mySerial);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
Serial.println("init done...");
}
void loop()
{
// now, i'm kinda lost here..
delay(100);
Serial.println("loop end.");
}
I am confused with most of the class method without a proper explanation.
modbusObj.readWriteMultipleRegisters();
modbusObj.writeSingleRegister();
modbusObj.setTransmitBuffer();
modbusObj.readCoils();
modbusObj.writeMultipleRegisters();
modbusObj.readHoldingRegisters();
// etc..
They had no documentation. Well, Some method names are self explanatory but not about the arguments.I am trying just to read the holding register.
TL;DR:
I want to read the level meter's distance data, but the library doesn't provide a proper documentation.
Nb:
nothing wrong with the ultrasonic device, tested in PC to read holding register with some modbus tool and hooked up to rs485 to usb and working!
this question intended in stack overflow rather than stack-electrical-engineering because I am mainly asking about the code.
I've been discussing it with someone in a local facebook forum that said he's successfully utilizing the lib alongside soft-serial and pro-mini.

Data are not sent between Arduino uno and NodeMcu esp8266 at all time

I am sending data from Arduino UNO R3 to nodeMcu esp8266. In that case sometime data are send properly but at sometime data are are not send by arduino or not get by nodemcu esp8266.Also tx light not blinks after i upload the code to the Arduiono.
enter code here
Code Uploaded to Arduino:
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial s(10,11);
SoftwareSerial h(10,11);
int i=0;
void setup() {
// put your setup code here, to run once:
s.begin(9600);
Serial.begin(9600);
}
int f1=0;
int f2=0;
String st="sy";
void loop() {
f1=f1+1;
f2=f2+2;
// put your main code here, to run repeatedly:
StaticJsonBuffer <1000> bf;
StaticJsonBuffer <1000> rec;
JsonObject& root=bf.createObject();
JsonObject& receives=rec.parseObject(h);
if (receives==JsonObject::invalid())
{
Serial.println("no data from nodemcu");
root["data3"]="no data from nide";
}
else
{
root["data3"] = receives["data3"];
//st = (const char*)receive["data3"];
}
root["data1"]=f1;
root["data2"]=f2;
//root["data3"]=st;
if(s.available()>0)
{
root.printTo(s);
Serial.println("send");
}
else
{
Serial.println("NOt Available");}
//i=i+1;
//s.write(i);
delay(1000);
}
In your code thera are two reasons I can spot on the first look:
1 Never use delay in server client applications. Delay stops proccessing and inhibts communication. For more details how to avoid look at the blinkwithoutdelay built in Example in the Arduino IDE.
2. You use ArduinoJSON: This lib is absolute overkill for 99% of the applications it is used for. Don't get me wrong - the lib offers fantastic features, but if not needed this can be regarded as bloat-ware.
I wrote my own simple JSON coding/decoding (~250 lines of code) for a performant application using an Arduino as "Signal generator" and the ESP8266/ESP32 as a webserver. Communication between Arduino and ESPis time critical and so far it works over a year without problems,

Using Modbus TCP on Arduino

I have a scd30 sensor wired to an arduino uno. The scd30 works on theh I2c protocol. I am able to read data live on the serial monitor on the arduino IDE. I have an ethernet shield on my arduino. I would like the arduino to communicate with a field agent which will upload the data to the internet.
I have tried numerous modbus tcp libraries and dont seem to be getting anywhere. I can connect my arduino to the field agent but whenever it sends data I get a 0x02 exception code - Illegal data address. This is the Library im using https://github.com/andresarmento/modbus-arduino/tree/master/libraries/ModbusIP/examples
I believe the right way to go about it is through holding registers but im not sure how to do this when using i2c. The connection is fine, the problem is the format. any help is appreciated thanks.
/*
Reading CO2, humidity and temperature from the SCD30
This example prints the current CO2 level, relative humidity, and temperature in C.
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Modbus.h>
#include <ModbusIP.h>
#include <Wire.h>
#include <Streaming.h>
#include "SparkFun_SCD30_Arduino_Library.h"
SCD30 airSensor;
//Modbus Registers Offsets (0-9999)
const int SENSOR_ISTS = 100;
//ModbusIP object
ModbusIP mb;
long ts;
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("SCD30 Example");
// The media access control (ethernet hardware) address for the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// The IP address for the shield
byte ip[] = { 000 , 00,0, 00 };
byte gateway[] = { 0, 0, 0, 0 };
byte subnet[] = { 255, 255, 255, 0 };
//Config Modbus IP
mb.config(mac, ip,gateway,subnet);
// Add SWITCH_ISTS register - Use addIsts() for digital inputs
mb.addHreg(SENSOR_ISTS);
airSensor.begin(); //This will cause readings to occur every two seconds
}
void loop()
{
mb.task();
mb.Hreg(SENSOR_ISTS, digitalRead(airSensor.getTemperature()));
}
I have read your problem.
In my view you first have to create a local server, somewhere like thingspace (https://thingspace.verizon.com/) or other online local servers, from there you can easily handle the data coming from the sensors.
You are using a code from library so it must be correct in any way. So, from my view you should check the data transactions.
wish my ans helps you
thanks!
The ModbusIP library expects from you that you supply the value of the register. The AirSensor library gives you that value.
Set the register value to Hreg:
mb.Hreg(SENSOR_ISTS, airSensor.getTemperature());
I tested your sketch without the sensor library and it is working. Client was my java test client I use to test access to Modbus TCP registers of my photovoltaic system.
Make sure that the client calls "0x03 - Read Holding Registers" and test address 100 and 101 because some modbus clients offsets are 1-based.

only 1 AT command sends (ESP8266/Arduino Uno)

I'm facing problem with sending AT Commands using Arduino Uno. I've written a small program (link below) to set up a server. I need to send data to Atmega from my laptop using Wifi module ESP8266. Everything would be fine if the entire program would do at once at the moment I need to comment and uncomment (adding and removing double slashes) every line of AT code, because only one AT command executes in a single compilation.
It seems like the program gets stuck somewhere in the while-loop (even on the module, I can see that blue diode stops blinking). I think that I've done something wrong in code and I would appreciate any help.
#include <SoftwareSerial.h>
SoftwareSerial espmod(2, 3);
void commands(String cmd, int waittime);
void setup(void) {
Serial.begin(9600);
espmod.begin(9600);
while (!Serial) {;}
commands("AT+GMR\r\n", 1000);
commands("AT+RST\r\n", 500);
commands("AT+CWMODE=1\r\n", 500);
commands("AT+CWJAP=\"SSID\",\"PASS\"\r\n", 4000);
commands("AT+CIPMUX=1\r\n", 500);
commands("AT+CIPSERVER=1,333\r\n", 500);
commands("AT+CIFSR\r\n", 500);
}
void loop() { // run over and over
}
void commands(String cmd, int waittime) {
espmod.print(cmd);
delay(waittime);
while(espmod.available()) {
char val = espmod.read();
Serial.write(val);
}
}
Here's the screen:
Version:
AT Version: 0.21.0.0
SDK Version: 0.9.5
Connections:
ESP
VCC -- 3,3 V (external source)
GND -- GND -- Arduino GND
RX -- TX (Arduino pin 3)
TX -- RX (Arduino pin 2)
CH_PD -- 3,3 V
RST -- 3,3 V
EDIT:
I've been fighting with this for couple of days, still without solution, but today it worked finally, but only once (after reseting power supply it's still the same) ! I could've seen all commands doing on SerialMonitor, so there is everything fine with code and i guess there is something wrong with esp module. As far as i can get only one AT command sent and executed in a single compilation, is it possible that 0,5 A current i provide to the module is not enough? Can module be out of the memory ? Is there any way to see SoftwareSerial monitor (is there anything like that)?
There is an unnecessary loop in command function. Let the arduino handle the loop for you. Also it is better to try with different delay parameters, maybe you can decrease some. Here the code I offer :
void loop() {
while (espmod.available()){
String result = espmod.readStringUntil('\n');
Serial.println("AT result : " + result);
}
}
void commands(String cmd, int waittime) {
espmod.print(cmd);
delay(waittime);
}

Sending AT commands to a GSM/GPRS and displaying the reply on a Serial Monitor

I am quite rusty when it comes to Serial ports. I want to send an AT command to a GSM/ GPRS shield connected to my Arduino UNO. The AT command I want to pass in particular is the command to get a networks signal strength.
I am using the SIM900 and SoftwareSerial library to send the command as the GSM library does not compile correctly for me. Meaning I have to use the SoftwareSerial library.
I have this example code from the SIM900 library working that relies on reading inputs from the serial monitor to carry out commands but I need it to be automated and the command to be passed in hardcoded. In this example code, the place of interest is the simplehwread() method.
#include "SIM900.h"
#include <SoftwareSerial.h>
int numdata;
char inSerial[40];
int i=0;
void setup()
{
//Serial connection.
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");
else Serial.println("\nstatus=IDLE");
};
void loop()
{
//Read for new byte on serial hardware,
//and write them on NewSoftSerial.
serialhwread();
//Read for new byte on NewSoftSerial.
serialswread();
};
void serialhwread()
{
i=0;
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i]=(Serial.read());
delay(10);
i++;
}
inSerial[i]='\0';
if(!strcmp(inSerial,"/END")) {
Serial.println("_");
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if(!strcmp(inSerial,"TEST")) {
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
} else {
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0]='\0';
}
}
void serialswread()
{
gsm.SimpleRead();
}
No matter how I modify this code, the command does not get passed in and response displayed while the method here does it but not the way I want it to be done. i.e Direct input. Could anyone assist here?
i have dealt with exactly this scenario at a company with a cellular radio on board. there are many status signals that come over and if not dealt with appropriately these status flags from the cell modem will be lost
you need to look at the data sheets associated with your cell modem and its protocol so you know what flags to watch for at the various steps taken along the way from configuration, to eventual connection to cellular service.
multi-threaded coding techniques must be followed as well.
keep in mind that the comm channel is not ideal and there WILL be failures. provided your coding techniques are sound and you follow protocol requirements, then it should work.
Ron
Boise, ID

Resources