Show Posts
Pages: 1 [2] 3 4 5
16  Using Arduino / Programming Questions / add number to long int on: September 10, 2013, 01:23:43 pm
Hi,
    all i want is to add a number before the code that the sensor send. here the code:
Code:
/*
  Simple example for receiving
 
  http://code.google.com/p/rc-switch/
 
  Need help? http://forum.ardumote.com
*/

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();
long int sensorcode;
long int type_sensor = 1;

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  Serial.println("No RF");
}

void loop() {
  if (mySwitch.available()) {
   
    int value = mySwitch.getReceivedValue();
   
    if (value == 0) {
      Serial.print("Unknown encoding");
    } else {
      sensorcode = type_sensor , (mySwitch.getReceivedValue());
      Serial.println (sensorcode) ;
    }
    delay(3000);
      Serial.println("No_rf");
    mySwitch.resetAvailable();
  }
}

Probably very stupid but it only show 1 without the rest of the code

What i want is if code is 45454545 change it to 145454545
Thanks
Mic
17  Using Arduino / Programming Questions / Read serial from serialsoftware on: August 26, 2013, 02:43:12 pm
Hi,
    here my problem, I got a little home automation box that send data trough serial. I want to read these data to eventually use it with the arduino, for now, all i want is to read these output, since i only got a uno and nano, both only have one serial rx/tx. So i use one to plug in the box and the other on my laptop to read the data with the software serial library. the only data that it show on the screen when i press a button on my box is some garbage like some yyyyyy. here's my code:

Code:
/*
  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 2 (connect to TX of other device)
 * TX is digital pin 3 (connect to RX of other device)
 
 created back in the mists of time
 modified 9 Apr 2012
 by Tom Igoe
 based on Mikal Hart's example
 
 This example code is in the public domain.
 
 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() 
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

 
  Serial.println("Start reading");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
}

And the other

And the other

Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 4); // RX, TX

void setup() 
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
}

void loop()
{
    if (Serial.available())
    mySerial.write(Serial.read());
}

tx to rx
rx to tx
gnd to gnd
vin to vin

Thanks in advance
18  Using Arduino / Networking, Protocols, and Devices / Re: Unstable Connection ENC28J60 / HanRun HR911105A with Nano on: March 14, 2013, 10:06:15 am
Did you guy manage a solution for this problem?

Thanks
19  Using Arduino / Programming Questions / Re: dtostrf with 0 value give error when send http on: March 10, 2013, 06:57:35 pm
Mistake by me i always have bad request event if temp is more the 1 degree, If i put it manually like this everything is find and update:
Code:
ether.browseUrl(PSTR("/data_request?id=variableset&DeviceNum=48&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value=7"), "", website, my_callback);

How the do i include the temerature after the=
20  Using Arduino / Programming Questions / Re: dtostrf with 0 value give error when send http on: March 10, 2013, 06:42:16 pm
Maybe that when it convert the 0 in the first bytes, bytes is null? Could that be my problem and if so could a byte be 0 not null.
21  Using Arduino / Programming Questions / Re: dtostrf with 0 value give error when send http on: March 10, 2013, 06:39:55 pm
If value of the sensor is more then 1 , data is send to the server and i receive a ok message. as soon as the temperature is 0, i receive a bad request error 400.
22  Using Arduino / Programming Questions / Re: dtostrf with 0 value give error when send http on: March 10, 2013, 06:33:49 pm
Really dont understand your answer
23  Using Arduino / Programming Questions / dtostrf with 0 value give error when send http on: March 10, 2013, 06:28:53 pm
Hi again,
             could it be possible that when temperature is start with 0, it unable to send the url it give me a error?

Code:
if ((timing ==1) && (millis() > timer)) {
    timer = millis() + 5000;
    sensors.requestTemperatures();
    Serial.println();
    Serial.println("<<< REQ ");
    float sensor1 = (sensors.getTempCByIndex(1));
    char buffer[10];
    dtostrf(sensor1, 5, 2, buffer);
    Serial.println("Sensor2 temperature is:");
    Serial.println(buffer);
    timing = 0;
    delay(500);
    ether.browseUrl(PSTR("/data_request?id=variableset&DeviceNum=48&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value="), buffer, website, my_callback);
   
24  Using Arduino / Programming Questions / Re: Put long string in flash memory on: March 06, 2013, 08:45:39 pm
Thanks,
           yes it will help. could you tell me how to read it after that.
25  Using Arduino / Programming Questions / Re: itoa function with dot in on: March 04, 2013, 02:15:54 pm
got it thanks

Code:
  ether.packetLoop(ether.packetReceive());
  if (millis() > timer) {
    timer = millis() + 5000;
    sensors.requestTemperatures();
    Serial.println();
    Serial.println("<<< REQ ");
    float sensor1 = (sensors.getTempCByIndex(0));
    char buffer[10];
    dtostrf(sensor1, 5, 2, buffer);
    Serial.println(buffer);
    delay(500);
    ether.browseUrl(PSTR("/data_request?id=variableset&DeviceNum=38&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value="), buffer, website, my_callback);

I need to put a delay before sending the url cause it was giving me sometime some bad number.
26  Using Arduino / Programming Questions / itoa function with dot in on: March 04, 2013, 01:20:03 pm
Hi again,
             i finally got my sketche working with the enc28j60. Now i'm able to send to my domotic box the temperature of a one-wire sensor. The only problem that i have is it dont take in concideration the . and the to number next to it so if temperature is 21.56 only 21 will be sent.
Here the code:
Code:
void loop () {
  ether.packetLoop(ether.packetReceive());
  if (millis() > timer) {
    timer = millis() + 10000;
    sensors.requestTemperatures();
    Serial.println(sensors.getTempCByIndex(0));
    Serial.println();
    Serial.println("<<< REQ ");
    char myIntAsString[24]; // 7 bytes is enough to contain any int, including minus sign and terminating zero
    itoa((sensors.getTempCByIndex(0)), myIntAsString, 10);
    Serial.print(myIntAsString);
    ether.browseUrl(PSTR("/data_request?id=variableset&DeviceNum=38&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value="), myIntAsString, website, my_callback);
}
}


Here the result in the serial print:
Code:
P:  192.168.2.124
GW:  192.168.2.1
DNS: 192.168.2.1
SRV: 192.168.2.19
19.25

<<< REQ
19>>>
HTTP/1.1 200 OK
content-Type: text

...

So before convert it to a compatible const char*, sensor read 19.25, but it send 19.

Any idea
Thanks

 
27  Using Arduino / Programming Questions / Re: error: invalid conversion from 'char' to 'const char*' on: March 03, 2013, 07:33:27 pm
Thanks,
           i try what you say and now i'm able to compile it without error.
The problem now is that it give me a bad request. If i print the temp, it give me the temperature. If i replace the temp with "88", no error occur and value 88 is updated. I'm lost
28  Using Arduino / Programming Questions / Re: error: invalid conversion from 'char' to 'const char*' on: March 03, 2013, 07:09:27 pm
Try with int and float, same problem, ethercard seems to need a const char* in the formule: ether.browseUrl(PSTR.....
How could i declare a const char* that could be variable.

Thanks in advance
29  Using Arduino / Programming Questions / error: invalid conversion from 'char' to 'const char*' on: March 03, 2013, 06:49:29 pm
Hi all,

        My problem is i want to put a variable for the temperature but i have an error: error: invalid conversion from 'char' to 'const char'
 here the code:

Code:
// Demo using DHCP and DNS to perform a web client request.
// 2011-06-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
static uint32_t timer;

char website[] PROGMEM = "192.168.2.19";
static byte hisip[] = {192,168,2,19};
char temperature;

// called when the client request is complete
static void my_callback (byte status, word off, word len) {
  Serial.println(">>>");
  Ethernet::buffer[off+300] = 0;
  Serial.print((const char*) Ethernet::buffer + off);
  Serial.println("...");
}

void setup () {
  Serial.begin(57600);
  Serial.println("\n[webClient]");

  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
    Serial.println( "Failed to access Ethernet controller");
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip); 
  ether.printIp("DNS: ", ether.dnsip); 
  ether.copyIp(ether.hisip, hisip);
  ether.hisport = 3480;
  ether.printIp("SRV: ", ether.hisip);

  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
}

void loop () {
  ether.packetLoop(ether.packetReceive());
 
  if (millis() > timer) {
    timer = millis() + 10000;
    temperature = 77;
    Serial.println();
    Serial.print("<<< REQ ");
    ether.browseUrl(PSTR("/data_request?id=variableset&DeviceNum=49&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value="), temperature, website, my_callback);
}
}
30  Using Arduino / Programming Questions / Re: error compile my code on: February 27, 2013, 10:40:21 pm
Ok other method, let say i want to insert value in the url:

Code:
ether.browseUrl(PSTR("/data_request?id=action&DeviceNum=(((HERE))&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue="), "1", website, my_callback);
In python i use the s% function like this:
Code:
"/data_request?id=action&DeviceNum=%s&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=" $ devid
but is there a way in arduino code
thanks
Pages: 1 [2] 3 4 5