Arduino NRF24L01不发送特定字符串

时间:2018-06-10 14:14:19

标签: arduino communication arduino-uno arduino-ide

我在NRF24L01上使用arduinu uno发送字符串但它没有正确发送

发射器的代码

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
 Serial.begin(115200);
 radio.begin();
 radio.openReadingPipe(0, address);
 radio.setPALevel(RF24_PA_MIN);
 radio.setDataRate(RF24_250KBPS);
 radio.startListening();
}

void loop() {
 if (radio.available()) {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

Receiver的代码

import { Injectable } from '@angular/core';
import { AngularFireDatabase, AngularFireList, AngularFireObject } from 'angularfire2/database';

import { AngularFireAuth } from 'angularfire2/auth';
import { Observable } from 'rxjs/Observable';
import { AuthService } from '../services/auth.service';
import * as firebase from 'firebase/app';
import {map} from 'rxjs/operators';
import { ChatMessage } from '../models/chat-message.model';
import { User } from 'src/app/models/user.model';

@Injectable()
export class ChatService {
  user: firebase.User;
  users : Observable<User[]>;
  chatMessages: AngularFireObject<ChatMessage[]>;
  chatMessage: ChatMessage;
  userName: Observable<string>;
  usersRef: AngularFireList<any>;

  constructor(
    private db: AngularFireDatabase,
    private afAuth: AngularFireAuth
  ) {

    this.usersRef = db.list('users');
    this.users = this.usersRef.snapshotChanges().pipe(
      map(changes => 
        changes.map(c => ({ key: c.payload.key, ...c.payload.val() }))
      )
    );
    this.afAuth.authState.subscribe(auth => {
      if (auth !== undefined && auth !== null) {
        this.user = auth;
      }

      // this.getUser().subscribe(a => {
      //   this.userName = a.displayName;
      // });
    });
  }

  getUser() {
    const userId = this.user.uid;
    const path = `/users/${userId}`;
    return this.db.object(path);
  }

  getUsers() {
    return this.users;

  }

  sendMessage(msg: string) {
    const timestamp = this.getTimeStamp();
    const email = this.user.email;
    this.chatMessages = this.getMessages();
    this.chatMessages.push({
      message: msg,
      timeSent: timestamp,
      userName: this.userName,
      email: email
    });
  }

  getMessages(): AngularFireObject<ChatMessage[]> {
    // query to create our message feed binding
    return this.db.list('messages', {
      query: {
        limitToLast: 25,
        orderByKey: true
      }
    });
  }

  getTimeStamp() {
    const now = new Date();
    const date = now.getUTCFullYear() + '/' +
      (now.getUTCMonth() + 1) + '/' +
      now.getUTCDate();
    const time = now.getUTCHours() + ':' +
      now.getUTCMinutes() + ':' +
      now.getUTCSeconds();

    return (date + ' ' + time);
  }
}

但它没有打印&#34; hhh&#34;它会像在图像中一样打印随机符号 enter image description here

0 个答案:

没有答案