Pages: [1]   Go Down
Author Topic: VirtualWire + M2tklib: issues  (Read 241 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HI all,
I'm using VirtualWire library for send data in ASK via M2tklib.
From my menù (i posted the part relative to this button menù because the sketch it's too long)...
just for explain you a little bit. I select from a menu the devices number and the state 0 off and 1 on . Then if 0 send out 0, if 1 send out 32 ... the receiver take a message and then calculate the devices and the state and then send back the state to the menu.
From the receiver part it's working perfectly ... from the menu side I've this issue:

- the first time I click ok button,send out message, I receive the "back message" the buf is in "unknown state" because i try print to print it and it's void (but the receiver has processed the message that I've send out correclty).
- the second time, I click the ok button, send out message,  I receive the "back message" the buf if I've send out 1 (32) is void (but the receiver has processed the message that I've send out correclty).
- the third time that I click ok button, send out message, I receive the "back message" the buf is correctly.( the receiver process message in the right way)
- the four time that I click ok button, send out message with "inverse state" (if was turn on, then turn off), the buf contain again turn on state ...
 
Menu Code Button:
Code:
void dev_ok_button(m2_el_fnarg_p fnarg) {

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  byte msgrx;
  byte devcalcolata;
  byte stato;
  
    if (u8stato == 0) // if state is 0 then I send out 0 this means shutdown devices
      {  
        array[u8dev][12] = 0;
        array[u8dev][0] = u8dev;
        TxMsg(array[u8dev][0]);
       }
    else
    if (u8stato == 1) // if state is 1 then i send out 32 that means turn on devices
      {  
        array[u8dev][0] = u8dev;
        array[u8dev][12] = 32;
        TxMsg((array[u8dev][0] + 32));  
        // m2_SetRoot(&m2_null_element);
        // m2_SetRoot(&top_el_expandable_menu);
      }
           // ProcessaMessaggio();
           // Alza il Piedino 12 a +5V per Arduino
                  
                  digitalWrite(12, true);
                  // Wait for a message
                  //vw_wait_rx();
                  if (vw_get_message(buf, &buflen)) // Non-blocking
                   {
                   msgrx = buf[0];
                   Serial.println("Message is arriving ...");
                   Serial.println(msgrx);    
                   devcalcolata = msgrx & 31;
                   Serial.println("Calculate Devices ");
                   Serial.println(devcalcolata);
                   Serial.println("Devices Stored ");
                   Serial.println(u8dev);
                   Serial.println("Device State ");
                   stato = msgrx & 32;
                   Serial.println(stato);    
                   }      
}

Receiver Code Button:
Code:
void ProcessaMessaggio()
{
   // Carica Messaggio nel buffer
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  // Alza il Piedino 12 a +5V per Arduino
  digitalWrite(12, true);
  // Wait for a message
  //vw_wait_rx();
  if (vw_get_message(buf, &buflen)) // Non-blocking
   {
     msgrx = buf[0];
     Serial.println("Message is arriving ");
     Serial.println(msgrx);
    
     devcalcolata = msgrx & 31;
    
     Serial.println("Calculate Devices ");
     Serial.println(devcalcolata);
    
     Serial.println("Devices Stored  ");
     Serial.println(dev);
    
     Serial.println("Devices State ");
     stato = msgrx & 32;
     Serial.println(stato);
    
   if (devcalcolata == dev)
    {
     Serial.println("Debug : Pass from here");
     byte mex;
     switch (stato) {
      case 0:
         buttonstate = 0;
         Serial.println("Turn Off Devices ");
         digitalWrite(13,0);
         mex = dev + buttonstate;        
         vw_send(&mex, 1);
         vw_wait_tx(); // Wait until the whole message is gone
      
         // Se lo Stato è diverso scrivi memorizza il dato nella eeprom    
         if (buttonstate != EEPROM.read(address))  // buttonstate != readEEPROM(disk1,address)
          {    
           EEPROM.write(address, buttonstate);
           // writeEEPROM(disk1, address, buttonstate);
           Serial.println("Previous States <> TurnOff");
          }
          // statements
          break;
       case 32:
          buttonstate = 32;
          Serial.println("Turn On Devices ");
          digitalWrite(13, buttonstate);
          mex = dev + buttonstate;
          vw_send(&mex, 1);
          vw_wait_tx(); // Wait until the whole message is gone  
          // Se lo Stato è diverso scrivi memorizza il dato nella eeprom
          if (buttonstate != EEPROM.read(address)) // buttonstate != readEEPROM(disk1,address)
           {    
            Serial.println("Previous State Off");
            // writeEEPROM(disk1,address, buttonstate);
            EEPROM.write(address, buttonstate);
           }
            break;
        }
    }
    }
}

So, I think that the problem is by menu side but I don't where is the issues, I'm going crazy i from 8 hours that I work on that without success ...seems that the buffer is not emptied after that I received message ... it's very strange issues ...

Someone can help kindly me ? I can give you also all the sketch if is necessary ... I can do a zip files ...everything ...

thanks gnux
« Last Edit: February 12, 2013, 12:39:54 pm by gnusso » Logged

Pages: [1]   Go Up
Jump to: