Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // UDP Port used for two way communication
- unsigned int localPort = 8888;
- UDP udp;
- const size_t maxPacketSize = 256;
- uint8_t packetBuffer[maxPacketSize];
- IPAddress ip(192,168,178,20); // ip of the computer running photontest.py
- uint32_t last;
- uint32_t count = 0;
- const uint32_t interval = 20000;
- void send_count(IPAddress& ip, int port){
- udp.beginPacket(ip, port);
- String countstr(count, DEC);
- countstr.getBytes(&packetBuffer[0], maxPacketSize);
- size_t count_length = countstr.length();
- packetBuffer[count_length] = ' ';
- udp.write(&packetBuffer[0], count_length+1);
- udp.endPacket();
- }
- void setup() {
- Serial.begin(9600);
- udp.begin(localPort);
- last = millis();
- }
- void loop() {
- auto now = millis();
- // not wrap around safe but that only happens every 50 days
- // and this is a simple hack
- if(now - last >= interval) {
- last = now;
- send_count(ip, 8888);
- count++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement