I am trying to post an object to my parse.com app from my arduino yun and it needs to post a new object every second. So far I have been able to post every 10 seconds but I cannot seem to get the arduino to post any faster than that. I tried looking into the parse library but don't see what would be slowing it down. I am using the parse library given in the guide at https://www.parse.com/docs/arduino/guide.
here is the code I have so far.
#include <Parse.h>
#include <Bridge.h>
#include <arduino.h>
ParseObjectCreate create;
void setup() {
Serial.begin(9600);
parseInit();
}
void loop() {
parseFunc(24); // just send 24 everytime for testing
}
void parseInit()
{
Bridge.begin();
while (!Serial); // wait for a serial connection
Parse.begin("**********", "***********"); //my parse keys
create.setClassName("Temperature");
}
void parseFunc(float tempC)
{
create.add("temperature", tempC);
ParseResponse response = create.send();
response.close();
}
You are probably being rate limited by Parse. The code executed in loop() is executed as quickly as the micro controller can execute it - which is very fast. As a result, you are trying to write to Parse many many more times than once a second. Try putting a call to delay() after parseFunc(24). Something like:
parseFunc(24);
delay(1000); //delay is in milliseconds
Let me know if it works!
Related
In order to measure the packet transmission/reception count, I declared a scalar variable and wrote a function related to record. It looks like this:
A.h
class VEINS_API A : public DemoBaseApplLayer
{
private:
long StaticsFrsaPacketCount;
cOutVector frsaPacketCountVector;
...
}
A.cc
void A::initialize(int stage)
{
DemoBaseApplLayer::initialize(stage);
if(stage == 0)
{
StaticsFrsaPacketCount = 0;
frsaPacketCountVector.setName("fR_SA packet count");
...
}
}
void A::finish()
{
recordScalar("fR_SA Packet", StaticsFrsaPacketCount);
...
}
void A::handleSelfMsg(cMessage* msg)
{
switch(msg -> getKind())
{
case SEND_FRSA_EVT:
{
...
StaticsFrsaPacketCount++;
frsaPacketCountVector.record(StaticsFrsaPacketCount);
...
sendDelayedDown(wsm, uniform(0.01, 0.50));
}
...
}
}
I wrote the code by referring to the statistics written in the official OMNeT++ Tictoc tutorial. However, the result of the scalar value through the generated .anf file after the simulation is finished is as shown in the image below.
In other words, it seems that the value is incremented 1 time and not incremented after that. What is the cause?
(this part) of your code looks fine. The most likely reason why you have 1 in the result because really just one packet was sent. The statistics are showing what is actually happening. If you expect several packets to be sent, I suggest to start the app in Qtenv and step over the simulation and make sure that it works as you expect.
I have basically connected a speaker to Arduino uno board. I just need help with the code. I have used the TMRpcm library to make it easier. However, it seems to be giving me an error everytime. here is the code below.
include "SD.h"
define SD_ChipSelectPin 10
include "TMRpcm.h"
include "SPI.h"
TMRpcm audio;
void setup(){
audio.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
audio.setVolume(10);
audio.play("Spring_In_My_Step_-_Silent_Partner_Mp3Converter_ne.wav");
}
void loop()
{
}
any and all help is appreciated
thank you!
import processing.serial.*;
String COM5;
Serial myPort;
String val;
void setup() {
String portName=COM5;
myPort= new Serial(this,portName,9600);
}
void draw() {
if(myPort.available()>0){
val=myPort.readStringUntil('\n');
}
println(val);
}
This is my code, I have copied from a website. when I try running it is showing
Error opening serial port null:null not permitted
I am badly in need of answer to go forward in my thermal imaging project.
You never give COM5 a value, so it's null. Then you pass that into the Serial() constructor. The Serial() constructor doesn't know what do do with a null value, so you get the error.
Please take a step back and read a tutorial on using the Serial library. The official documentation contains example code that uses the Serial() constructor correctly.
COM5 hasn't got a value as a String.
Try this in Processing:
import processing.serial.*;
Serial myPort;
String val;
void setup() {
myPort= new Serial(this, "COM5", 9600);
}
void draw() {
if (myPort.available()>0) {
val=myPort.readStringUntil('\n');
}
println(val);
}
Double check your Arduino appears as COM5 in Device Manager and you don't have Arduino's Serial Monitor open when you run the Processing sketch.
In a project, we try to set up a communication network between three ATtinys, where the first must receive messages from the other two. Those other two tinys are connected to two different pins of the first tiny. The first tiny must then receive two strings from the other tinys, one from each, and send it to an Arduino. For the communication we used SoftwareSerial. We managed to receive and send the input from one tiny, but not from both of them, because we could not find a way to read the input from only one specific pin at a time.
This is the code we used:
#include <SoftwareSerial.h>
const int rx=4;
const int rx2=1;
const int tx=3;
const int tx2=3;
SoftwareSerial mySerial(rx,tx);
SoftwareSerial mySerial2(rx2,tx2);
void setup()
{
pinMode(rx,INPUT);
pinMode(rx2,INPUT);
pinMode(tx,OUTPUT);
mySerial.begin(9600);
mySerial2.begin(9600);
}
void loop()
{
mySerial.listen();
if (mySerial.isListening()) {
mySerial.println("Port One is listening!");
mySerial.println(mySerial.read());
}
else{
mySerial.println("Port One is not listening!");
}
mySerial2.listen();
if (mySerial2.isListening()) {
mySerial2.println("Port Two is listening!");
mySerial2.println(mySerial2.read());
}
else{
mySerial2.println("Port Two is not listening!");
}
delay(500);
}
The code above worked without the part after mySerial2.listen();. Maybe the listen-function of SoftwareSerial does not work on the tinys, but if that is the case, is there another way to listen to a specific input pin?
Or do you have any advice what to do?
I was going over the examples of boost.asio and I am wondering why there isn't an example of a simple server/client example that prints a string on the server and then returns a response to the client.
I tried to modify the echo server but I can't really figure out what I'm doing at all.
Can anyone find me a template of a client and a template of a server?
I would like to eventually create a server/client application that receives binary data and just returns an acknowledgment back to the client that the data is received.
EDIT:
void handle_read(const boost::system::error_code& error,
size_t bytes_transferred) // from the server
{
if (!error)
{
boost::asio::async_write(socket_,
boost::asio::buffer("ACK", bytes_transferred),
boost::bind(&session::handle_write, this,
boost::asio::placeholders::error));
}
else
{
delete this;
}
}
This returns to the client only 'A'.
Also in data_ I get a lot of weird symbols after the response itself.
Those are my problems.
EDIT 2:
Ok so the main problem is with the client.
size_t reply_length = boost::asio::read(s,
boost::asio::buffer(reply, request_length));
Since it's an echo server the 'ACK' will only appear whenever the request length is more then 3 characters.
How do I overcome this?
I tried changing request_length to 4 but that only makes the client wait and not do anything at all.
Eventually I found out that the problem resides in this bit of code in the server:
void handle_read(const boost::system::error_code& error,
size_t bytes_transferred) // from the server
{
if (!error)
{
boost::asio::async_write(socket_,
boost::asio::buffer("ACK", 4), // replaced bytes_transferred with the length of my message
boost::bind(&session::handle_write, this,
boost::asio::placeholders::error));
}
else
{
delete this;
}
}
And in the client:
size_t reply_length = boost::asio::read(s,
boost::asio::buffer(reply, 4)); // replaced request_length with the length of the custom message.
The echo client/server is the simple example. What areas are you having trouble with? The client should be fairly straightforward since it uses the blocking APIs. The server is slightly more complex since it uses the asynchronous APIs with callbacks. When you boil it down to the core concepts (session, server, io_service) it's fairly easy to understand.