espnowSimple 1
Loading...
Searching...
No Matches
cansat24write.ino
Go to the documentation of this file.
1/*
2* CANSAT NeXT kit based cansat - transmitter
3*/
4
5/* cansatdk
6*
7* cansatdk.cpp
8* ----------------------------------------------------------------------------
9* "THE BEER-WARE LICENSE":
10* <jensd@jensd.dk/jdn@es.aau.dk> wrote this file. As long as you retain this notice you
11* can do whatever you want with this stuff. If we meet some day, and you think
12* this stuff is worth it, you can buy me a beer in return.
13* Jens Dalsgaard Nielsen April 2024
14* ----------------------------------------------------------------------------
15* be inspired here : https://randomnerdtutorials.com/get-change-esp32-esp8266-mac-address-arduino/
16* and see http://jensd.dk/doc/esp32
17*
18* from http://cansat.fi ...
19* This example shows how data can be sent from the satellite to the groundstation.
20* The same functions work the other way around as well, and can be used to send data to the satellite from the groundstation.
21* Caution - You should always have an antenna in a radio system before transmitting anything. Make sure the antenna is plugged in before sending data via the radio.
22*
23* Links:
24 http://cansat.fi
25* https://dronebotworkshop.com/esp-now/
26*
27* http://jensd.dk/doc/cansat/cansatdk code etc for this page
28*/
29
30
31
32#include "CanSatNeXT.h"
33#include "cansatdk.h"
34
35#define NETID 72
36
37#define LEDPIN 5
38
39const unsigned long timePeriod = 500; // sampling every 100 millisecond
40unsigned long nextTime;
41
42uint8_t nodeMAC[6];
43
44void setup() {
45
46 Serial.begin(115200);
47 delay(100);
48
49 pinMode(LEDPIN, OUTPUT);
50
51 Serial.println("Jens 01");
52
53 getMACAddr(nodeMAC); // my personal ID
54
55 // Initialize CanSatNeXT systems.
56 // Calling this function with an address as a parameter enables the radio.
57 // The address is shared by both the transmitter and receiver.
58
59 CanSatInit(NETID); // NB netID must not end on 1,3,5,7,9
60
61 nextTime = millis() + timePeriod;
62}
63
64
65
66/*
67cansatDK datapkg
68
69typedef struct cansatdkPkg{
70float accX,accY,accZ,
71float gyroX,gyroY,gyroZ;
72float pressure;
73float temperature;
74int seqNr;
75uint8_t macAddr[6];
76bool SDcardAvailable;
77} cansatdkPkg;
78*/
79
80cansatdkPkg dataPkg;
81
82void fillDataPkg(cansatdkPkg *pkg) {
83 static int mySeqNr = 0;
84 readAcceleration((pkg->accX), (pkg->accY), (pkg->accZ));
85 readGyro((pkg->gyroX), (pkg->gyroY), (pkg->gyroZ));
86 pkg->pressure = readPressure();
87 pkg->temperature = readTemperature();
88 pkg->SDcardAvailable = SDCardPresent();
89 mySeqNr++;
90 memcpy(pkg->macAddr, nodeMAC, 6);
91 pkg->seqNr = mySeqNr;
92}
93
94int iii = 0;
95
96void loop() {
97
98 if (nextTime <= millis()) {
100
101 Serial.println(iii);
102 fillDataPkg(&dataPkg); // measure all sensors and pack them
103
104 sendData((char *)(&dataPkg), sizeof(dataPkg));
105 digitalWrite(LEDPIN, !digitalRead(LEDPIN));
106 }
107}
cansatdkPkg dataPkg
#define NETID
#define LEDPIN
unsigned long nextTime
void setup()
uint8_t nodeMAC[6]
void fillDataPkg(cansatdkPkg *pkg)
int iii
const unsigned long timePeriod
void loop()